Java Code Examples for org.bukkit.event.player.PlayerFishEvent#getState()

The following examples show how to use org.bukkit.event.player.PlayerFishEvent#getState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerFishListener.java    From IridiumSkyblock with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void onPlayerFish(PlayerFishEvent event) {
    try {
        final Player player = event.getPlayer();
        final Location location = player.getLocation();
        final IslandManager islandManager = IridiumSkyblock.getIslandManager();
        if (!islandManager.isIslandWorld(location)) return;

        if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return;

        final User user = User.getUser(player);
        final Island island = user.getIsland();
        if (island == null) return;

        for (Mission mission : IridiumSkyblock.getMissions().missions) {
            final Map<String, Integer> levels = island.getMissionLevels();
            levels.putIfAbsent(mission.name, 1);

            final MissionData level = mission.levels.get(levels.get(mission.name));
            if (level.type == MissionType.FISH_CATCH)
                island.addMission(mission.name, 1);
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().sendErrorMessage(e);
    }
}
 
Example 2
Source File: Scout.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
	public void Grappler(PlayerFishEvent event)
	{
		Player player = event.getPlayer();
		if(event.getState() == State.IN_GROUND)
		{
			AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
			if(p != null && p.getKit().equals(this))
			{
				if(isGrappleItem(player.getItemInHand()))
				{
					//event.getHook().
					Location playerloc = player.getLocation();
					Location loc = event.getHook().getLocation();
					if (playerloc.distance(loc) < 3.0D) 
				        pullPlayerSlightly(player, loc);
				    else 
				        pullEntityToLocation(player, loc);
//					Vector vec = playerloc.toVector();
//					Vector vec2 = loc.toVector();
//					player.setVelocity(vec2.subtract(vec).normalize().multiply(1));
					player.getItemInHand().setDurability((short)0);
				}
			}
		}
	}
 
Example 3
Source File: DisplayProtectionListener.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void player(PlayerFishEvent event) {
    if (DisplayItem.getNowUsing() != DisplayType.REALITEM) {
        return;
    }
    if (event.getState() != State.CAUGHT_ENTITY) {
        return;
    }
    if (event.getCaught() == null) {
        return;
    }
    if (event.getCaught().getType() != EntityType.DROPPED_ITEM) {
        return;
    }
    final Item item = (Item) event.getCaught();
    final ItemStack is = item.getItemStack();
    if (!DisplayItem.checkIsGuardItemStack(is)) {
        return;
    }
    // item.remove();
    event.getHook().remove();
    // event.getCaught().remove();
    event.setCancelled(true);
    sendAlert(
            "[DisplayGuard] Player "
                    + event.getPlayer().getName()
                    + " trying hook item use Fishing Rod, QuickShop already removed it.");
    Util.inventoryCheck(event.getPlayer().getInventory());
}
 
Example 4
Source File: CustomItemFish.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onCustomItemFish(CustomItemFishEvent customEvent) {
	if (customEvent.isCancelled())
		return;
	CustomItem cItem = customEvent.getCustomItem();
	PlayerFishEvent event = customEvent.getPlayerFishEvent();
	Player player = event.getPlayer();
	if (cItem.getDurabilityMechanics() instanceof FishingRodDurability) {
		ItemStack item = customEvent.getCustomItemStack().getItemStack();
		State state = event.getState();
		FishingRodDurability mechanics = (FishingRodDurability) cItem.getDurabilityMechanics();
		PlayerCustomItemDamageEvent damageEvent = new PlayerCustomItemDamageEvent(player, item, 0, cItem);

		switch (state) {
		case CAUGHT_ENTITY:
			if (event.getCaught().getType() == EntityType.DROPPED_ITEM) {
				damageEvent.setDamage(mechanics.getItemReel());
			} else {
				damageEvent.setDamage(mechanics.getEntityReel());
			}
			break;
		case CAUGHT_FISH:
			damageEvent.setDamage(mechanics.getFishCatch());
			break;
		case IN_GROUND:
			damageEvent.setDamage(mechanics.getBlockReel());
			break;
		default:
			break;
		}

		if (damageEvent.getDamage() != 0)
			Bukkit.getServer().getPluginManager().callEvent(damageEvent);
	}
}
 
Example 5
Source File: InhumanReactionPattern.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected int process(User user, PlayerFishEvent event)
{
    switch (event.getState()) {
        case CAUGHT_FISH:
            // Too few time has passed since the fish bit.
            if (user.getTimestampMap().recentlyUpdated(TimestampKey.LAST_FISH_BITE, fishingMilliseconds)) {

                // Get the correct amount of vl.
                // vl 6 is the maximum.
                // Points = {{0, 1}, {8, 0}}
                // Function: 1 - 0.125x
                for (byte b = 5; b > 0; b--) {
                    if (user.getTimestampMap().recentlyUpdated(TimestampKey.LAST_FISH_BITE, (long) (1 - 0.125 * b) * fishingMilliseconds)) {
                        // Flag for vl = b + 1 because there would otherwise be a "0-vl"
                        message = "AutoFish-Verbose | Player " + user.getPlayer().getName() + " failed inhuman reaction";
                        return b + 1;
                    }
                }
            }

            // Reset the bite-timestamp to be ready for the next one
            user.getTimestampMap().nullifyTimeStamp(TimestampKey.LAST_FISH_BITE);
            break;
        case BITE:
            user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_FISH_BITE);
            break;
        default:
            break;
    }
    return 0;
}
 
Example 6
Source File: FishingTaskType.java    From Quests with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onFishCaught(PlayerFishEvent event) {
        if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) {
            return;
        }

//        Location hookLocation = event.getHook().getLocation().add(0, -1, 0);
//        if (!(hookLocation.getBlock().getType() == Material.WATER)) {
//            return;
//        }
        
        Player player = event.getPlayer();

        QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true);
        QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();

        for (Quest quest : super.getRegisteredQuests()) {
            if (questProgressFile.hasStartedQuest(quest)) {
                QuestProgress questProgress = questProgressFile.getQuestProgress(quest);

                for (Task task : quest.getTasksOfType(super.getType())) {
                    TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());

                    if (taskProgress.isCompleted()) {
                        continue;
                    }

                    int catchesNeeded = (int) task.getConfigValue("amount");

                    int progressCatches;
                    if (taskProgress.getProgress() == null) {
                        progressCatches = 0;
                    } else {
                        progressCatches = (int) taskProgress.getProgress();
                    }

                    taskProgress.setProgress(progressCatches + 1);

                    if (((int) taskProgress.getProgress()) >= catchesNeeded) {
                        taskProgress.setCompleted(true);
                    }
                }
            }
        }
    }
 
Example 7
Source File: ConsistencyPattern.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected int process(User user, PlayerFishEvent event)
{
    switch (event.getState()) {
        case FISHING:
            // Not too many failed attempts in between (afk fish farm false positives)
            // Negative maximum_fails indicate not allowing afk fishing farms.
            if ((maximumFails < 0 || user.getFishingData().failedCounter <= maximumFails) &&
                // If the last attempt was a fail do not check (false positives)
                user.getTimestampMap().getTimeStamp(TimestampKey.AUTOFISH_DETECTION) != 0 &&
                // Add the delta to the consistencyBuffer of the user.
                user.getFishingData().bufferConsistencyData())
            {
                // Enough data, now checking
                final DoubleStatistics consistencyStatistics = user.getFishingData().getStatistics();

                // Calculate the maximum offset.
                final double maxOffset = Math.max(MathUtils.offset(consistencyStatistics.getMin(), consistencyStatistics.getAverage()), MathUtils.offset(consistencyStatistics.getMax(), consistencyStatistics.getAverage()));

                // Ceil in order to make sure that the result is at least 1
                final double flagOffset = Math.ceil((violationOffset - maxOffset) * 0.5D);

                message = "AutoFish-Verbose | Player " +
                          user.getPlayer().getName() +
                          " failed consistency | average time: " +
                          StringUtils.limitStringLength(String.valueOf(consistencyStatistics.getAverage()), 7) +
                          " | maximum offset: " +
                          StringUtils.limitStringLength(String.valueOf(maxOffset), 7) +
                          " | flag offset: " +
                          StringUtils.limitStringLength(String.valueOf(flagOffset), 7);

                user.getFishingData().getStatistics().reset();

                // Has the player violated the check?
                return (int) Math.max(flagOffset, 0);
            }

            // Reset the fail counter as just now there was a fishing success.
            user.getFishingData().failedCounter = 0;
            break;
        // No consistency when not fishing / failed fishing
        case IN_GROUND:
        case FAILED_ATTEMPT:
            user.getTimestampMap().nullifyTimeStamp(TimestampKey.AUTOFISH_DETECTION);
            user.getFishingData().failedCounter++;
            break;
        case CAUGHT_FISH:
            // CAUGHT_FISH covers all forms of items from the water.
            user.getTimestampMap().updateTimeStamp(TimestampKey.AUTOFISH_DETECTION);
            break;
        default:
            break;
    }
    return 0;
}