예제 #1
0
  /**
   * Monitor PlayerFish events.
   *
   * @param event The event to watch
   */
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
  public void onPlayerFish(PlayerFishEvent event) {
    Player player = event.getPlayer();

    if (Permissions.getInstance().fishing(player)) {
      State state = event.getState();

      switch (state) {
        case CAUGHT_FISH:
          Fishing.processResults(event);
          break;

        case CAUGHT_ENTITY:
          if (!(event.getCaught() instanceof LivingEntity)) {
            return;
          }

          if (Users.getProfile(player).getSkillLevel(SkillType.FISHING) >= 150
              && Permissions.getInstance().shakeMob(player)) {
            Fishing.shakeMob(event);
          }
          break;

        default:
          break;
      }
    }
  }
예제 #2
0
 @EventHandler
 public void onPlayerFished(PlayerFishEvent event) {
   Player player = event.getPlayer();
   if (this.pl.kit)
     if ((this.pl.km.temKit(player))
         && (this.pl.km.getPlayerKit(player, this.pl.km.getKitByName("Fisherman")))
         && ((event.getCaught() instanceof Player))) {
       Player caught = (Player) event.getCaught();
       if (player.getItemInHand().getType() == Material.FISHING_ROD) {
         caught.teleport(player.getLocation());
       }
     }
 }
예제 #3
0
 @EventHandler
 public void onFish(PlayerFishEvent event) {
   Player player = event.getPlayer();
   ItemStack itemStack = player.getItemInHand();
   if (itemStack == null) {
     return;
   }
   if (itemStack.getType() == Material.AIR) {
     return;
   }
   ItemMeta meta = itemStack.getItemMeta();
   if (meta == null) {
     return;
   }
   Map<Enchantment, Integer> enchants = meta.getEnchants();
   if (enchants == null) {
     return;
   }
   if (enchants.isEmpty()) {
     return;
   }
   for (Entry<Enchantment, Integer> entry : enchants.entrySet()) {
     Enchantment enchantment = entry.getKey();
     if (enchantment instanceof IEnchant) {
       IEnchant enchant = (IEnchant) enchantment;
       enchant.onFish(event, entry.getValue());
     }
   }
 }
예제 #4
0
  @EventHandler
  void onPlayerFishEvent(PlayerFishEvent event) {
    if (event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY
        || event.getState() == PlayerFishEvent.State.CAUGHT_FISH) {
      if (new Random().nextInt(100) < 10) {
        ItemStack item;

        if (new Random().nextInt(2) == 1) {
          item = new ItemStack(Material.NAME_TAG);
        } else {
          item = new ItemStack(Material.SADDLE);
        }
        event.getPlayer().getLocation().getWorld().dropItem(event.getPlayer().getLocation(), item);
      }
    }
  }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerFish(PlayerFishEvent event) {
    Player player = event.getPlayer();

    String ability = EntityTools.getBendingAbility(player);

    if (Bloodbending.isBloodbended(player) || Concussion.getTarget(player) != null) {
      event.setCancelled(true);
      return;
    }

    RegisteredAbility register = AbilityManager.getManager().getRegisteredAbility(ability);

    if (MetalBending.NAME.equals(ability) && EntityTools.canBend(player, register)) {
      MetalWire.pull(player, event.getHook());
    }
  }
예제 #6
0
파일: Fishing.java 프로젝트: bigggan/mcMMO
  /**
   * 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"));
      }
    }
  }
  @EventHandler(priority = EventPriority.NORMAL)
  public void fishing(PlayerFishEvent event) {
    PlayerFishEvent.State state = event.getState();
    Player p = event.getPlayer();
    ItemStack is = p.getItemInHand();
    Material mat = is.getType();
    Location loc = p.getLocation();

    if (contains(loc, x1, x2, y1, y2, z1, z2) == true) {

      if (mat == Material.FISHING_ROD) {

        if (state == State.IN_GROUND) {
          p.launchProjectile(Snowball.class);
        }
      }
    }
  }
예제 #8
0
  @EventHandler(priority = EventPriority.NORMAL)
  public void fishing(PlayerFishEvent event) {
    Player player = event.getPlayer();
    ItemStack itemStack = player.getItemInHand();
    Material material = itemStack.getType();
    Location location = player.getLocation();
    Location bobber = event.getHook().getLocation();

    if (location.getWorld().getName().equals(getName())) {

      if (material == Material.FISHING_ROD) {

        if (event.getHook().getVelocity().getY() < 0.02 && isLocationNearBlock(bobber)) {
          player.launchProjectile(Snowball.class);
        }
      }
    }
  }
예제 #9
0
  @EventHandler(priority = EventPriority.LOW)
  public void fishEvent(PlayerFishEvent event) {
    Player play = event.getPlayer();
    if (event.getCaught() == null) return;

    EntityType fish = event.getCaught().getType();

    if ((MCListeners.isMultiWorld())
        && (!play.hasPermission("mcjobs.world.all"))
        && (!play.hasPermission("mcjobs.world." + play.getWorld().getName()))) return;

    for (Map.Entry<String, PlayerJobs> en : PlayerJobs.getJobsList().entrySet()) {
      if (PlayerCache.hasJob(play.getName(), en.getKey())) {
        CompCache comp = new CompCache(en.getKey(), play.getLocation(), play, fish, "fishing");
        CompData.getCompCache().add(comp);
      }
    }
  }
예제 #10
0
파일: Fishing.java 프로젝트: bigggan/mcMMO
  /**
   * 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);
  }
예제 #11
0
파일: _37.java 프로젝트: r0306/RollTheDice
  @EventHandler
  public void onGrapple(PlayerFishEvent event)
      throws NoSuchFieldException, SecurityException, IllegalArgumentException,
          IllegalAccessException {

    final Player player = event.getPlayer();

    // if (isIn(player, 37))
    {
      if (event.getState() == State.IN_GROUND) {

        if (hooks.containsKey(player.getName())) {

          final Location location =
              hooks
                  .get(player.getName())
                  .getLocation(); // hooks.get(player.getName()).getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR ? hooks.get(player.getName()).getLocation() : hooks.get(player.getName()).getLocation().getBlock().getRelative(BlockFace.UP).getLocation();

          if (location.getBlock().getType() == Material.AIR
              || location.getBlock().getType() == Material.SNOW) {

            // player.setVelocity(hooks.get(player.getName()).getLocation().toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector()).normalize().multiply(new Vector(2, 2, 2)));
            // Projectile fishing = player.launchProjectile(Snowball.class);
            final Vector velocity =
                location
                    .toVector()
                    .subtract(player.getLocation().subtract(0, 1, 0).toVector())
                    .normalize()
                    .multiply(new Vector(2, 2, 2));

            if (Math.abs(location.getBlockY() - player.getLocation().getBlockY()) < 2
                && location.distance(player.getLocation()) > 4) {

              player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));

              Bukkit.getServer()
                  .getScheduler()
                  .scheduleSyncDelayedTask(
                      Plugin.getPlugin(),
                      new Runnable() {

                        @Override
                        public void run() {
                          player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));
                          // player.setVelocity(location.toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector().normalize().multiply(2)));

                        }
                      },
                      1L);

            } else {

              player.setVelocity(velocity);

              Bukkit.getServer()
                  .getScheduler()
                  .scheduleSyncDelayedTask(
                      Plugin.getPlugin(),
                      new Runnable() {

                        @Override
                        public void run() {
                          player.setVelocity(velocity.multiply(new Vector(1, 1, 1)));
                          // player.setVelocity(location.toVector().subtract(player.getLocation().subtract(0, 1, 0).toVector().normalize().multiply(0.5)));

                        }
                      },
                      0L);
            }
            // fishing.setPassenger(player);
            // projectiles.add(fishing);
          }
        }
      }
    }
  }
	@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
	public void onPlayerFishEvent(final PlayerFishEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());
		user.updateActivity(true);
	}
예제 #13
0
파일: Fishing.java 프로젝트: bigggan/mcMMO
  /**
   * Shake a mob, have them drop an item.
   *
   * @param event The event to modify
   */
  public static void shakeMob(PlayerFishEvent event) {
    final int DROP_NUMBER = random.nextInt(100);

    LivingEntity le = (LivingEntity) event.getCaught();
    EntityType type = le.getType();
    Location loc = le.getLocation();

    switch (type) {
      case BLAZE:
        m.mcDropItem(loc, new ItemStack(Material.BLAZE_ROD));
        break;

      case CAVE_SPIDER:
        if (DROP_NUMBER > 50) {
          m.mcDropItem(loc, new ItemStack(Material.SPIDER_EYE));
        } else {
          m.mcDropItem(loc, new ItemStack(Material.STRING));
        }
        break;

      case CHICKEN:
        if (DROP_NUMBER > 66) {
          m.mcDropItem(loc, new ItemStack(Material.FEATHER));
        } else if (DROP_NUMBER > 33) {
          m.mcDropItem(loc, new ItemStack(Material.RAW_CHICKEN));
        } else {
          m.mcDropItem(loc, new ItemStack(Material.EGG));
        }
        break;

      case COW:
        if (DROP_NUMBER > 99) {
          m.mcDropItem(loc, new ItemStack(Material.MILK_BUCKET));
        } else if (DROP_NUMBER > 50) {
          m.mcDropItem(loc, new ItemStack(Material.LEATHER));
        } else {
          m.mcDropItem(loc, new ItemStack(Material.RAW_BEEF));
        }
        break;

      case CREEPER:
        m.mcDropItem(loc, new ItemStack(Material.SULPHUR));
        break;

      case ENDERMAN:
        m.mcDropItem(loc, new ItemStack(Material.ENDER_PEARL));
        break;

      case GHAST:
        if (DROP_NUMBER > 50) {
          m.mcDropItem(loc, new ItemStack(Material.SULPHUR));
        } else {
          m.mcDropItem(loc, new ItemStack(Material.GHAST_TEAR));
        }
        break;

      case MAGMA_CUBE:
        m.mcDropItem(loc, new ItemStack(Material.MAGMA_CREAM));
        break;

      case MUSHROOM_COW:
        if (DROP_NUMBER > 99) {
          m.mcDropItem(loc, new ItemStack(Material.MILK_BUCKET));
        } else if (DROP_NUMBER > 98) {
          m.mcDropItem(loc, new ItemStack(Material.MUSHROOM_SOUP));
        } else if (DROP_NUMBER > 66) {
          m.mcDropItem(loc, new ItemStack(Material.LEATHER));
        } else if (DROP_NUMBER > 33) {
          m.mcDropItem(loc, new ItemStack(Material.RAW_BEEF));
        } else {
          m.mcDropItems(loc, new ItemStack(Material.RED_MUSHROOM), 3);
        }
        break;

      case PIG:
        m.mcDropItem(loc, new ItemStack(Material.PORK));
        break;

      case PIG_ZOMBIE:
        if (DROP_NUMBER > 50) {
          m.mcDropItem(loc, new ItemStack(Material.ROTTEN_FLESH));
        } else {
          m.mcDropItem(loc, new ItemStack(Material.GOLD_NUGGET));
        }
        break;

      case SHEEP:
        Sheep sheep = (Sheep) le;

        if (!sheep.isSheared()) {
          Wool wool = new Wool();
          wool.setColor(sheep.getColor());

          ItemStack theWool = wool.toItemStack();
          theWool.setAmount(1 + random.nextInt(6));

          m.mcDropItem(loc, theWool);
          sheep.setSheared(true);
        }
        break;

      case SKELETON:
        if (DROP_NUMBER > 50) {
          m.mcDropItem(loc, new ItemStack(Material.BONE));
        } else {
          m.mcDropItems(loc, new ItemStack(Material.ARROW), 3);
        }
        break;

      case SLIME:
        m.mcDropItem(loc, new ItemStack(Material.SLIME_BALL));
        break;

      case SNOWMAN:
        if (DROP_NUMBER > 99) {
          m.mcDropItem(loc, new ItemStack(Material.PUMPKIN));
        } else {
          m.mcDropItems(loc, new ItemStack(Material.SNOW_BALL), 5);
        }
        break;

      case SPIDER:
        if (DROP_NUMBER > 50) {
          m.mcDropItem(loc, new ItemStack(Material.SPIDER_EYE));
        } else {
          m.mcDropItem(loc, new ItemStack(Material.STRING));
        }
        break;

      case SQUID:
        m.mcDropItem(loc, new ItemStack(Material.INK_SACK, 1, (short) 0, (byte) 0x0));
        break;

      case ZOMBIE:
        m.mcDropItem(loc, new ItemStack(Material.ROTTEN_FLESH));
        break;

      default:
        break;
    }

    Combat.dealDamage(le, 1);
  }