mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 02:04:44 +02:00
Improve Fishing AFK detection
This commit is contained in:
@ -29,6 +29,7 @@ import com.gmail.nossr50.util.sounds.SoundManager;
|
||||
import com.gmail.nossr50.util.sounds.SoundType;
|
||||
import com.gmail.nossr50.worldguard.WorldGuardManager;
|
||||
import com.gmail.nossr50.worldguard.WorldGuardUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -331,21 +332,18 @@ public class PlayerListener implements Listener {
|
||||
fishingManager.setFishingTarget();
|
||||
}
|
||||
return;
|
||||
|
||||
case CAUGHT_FISH:
|
||||
if(fishingManager.exploitPrevention(event.getHook().getBoundingBox()))
|
||||
if(fishingManager.exploitPrevention(event.getHook().getLocation().toVector()))
|
||||
return;
|
||||
fishingManager.handleFishing((Item) caught);
|
||||
fishingManager.setFishingTarget();
|
||||
return;
|
||||
|
||||
case CAUGHT_ENTITY:
|
||||
if (fishingManager.canShake(caught)) {
|
||||
fishingManager.shakeCheck((LivingEntity) caught);
|
||||
fishingManager.setFishingTarget();
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import com.gmail.nossr50.util.random.RandomChanceUtil;
|
||||
import com.gmail.nossr50.util.skills.CombatUtils;
|
||||
import com.gmail.nossr50.util.skills.RankUtils;
|
||||
import com.gmail.nossr50.util.skills.SkillUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
@ -34,6 +35,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -57,13 +59,16 @@ public class FishingManager extends SkillManager {
|
||||
return getSkillLevel() >= RankUtils.getUnlockLevel(SubSkillType.FISHING_MASTER_ANGLER) && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.FISHING_MASTER_ANGLER);
|
||||
}
|
||||
|
||||
public boolean exploitPrevention(BoundingBox boundingBox) {
|
||||
public boolean exploitPrevention(Vector centerOfCastVector) {
|
||||
|
||||
Block targetBlock = getPlayer().getTargetBlock(BlockUtils.getTransparentBlocks(), 100);
|
||||
/*Block targetBlock = getPlayer().getTargetBlock(BlockUtils.getTransparentBlocks(), 100);
|
||||
|
||||
if (!targetBlock.isLiquid()) {
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
|
||||
if(lastFishingBoundingBox == null)
|
||||
lastFishingBoundingBox = makeBoundingBox(centerOfCastVector);
|
||||
|
||||
long currentTime = System.currentTimeMillis();
|
||||
boolean hasFished = (currentTime < fishingTimestamp + (FISHING_COOLDOWN_SECONDS * 10));
|
||||
@ -71,13 +76,21 @@ public class FishingManager extends SkillManager {
|
||||
if(hasFished)
|
||||
fishingTimestamp = currentTime;
|
||||
|
||||
boolean sameTarget = (lastFishingBoundingBox != null && lastFishingBoundingBox.overlaps(boundingBox));
|
||||
BoundingBox newCastBoundingBox = makeBoundingBox(centerOfCastVector);
|
||||
|
||||
lastFishingBoundingBox = boundingBox;
|
||||
boolean sameTarget = lastFishingBoundingBox.overlaps(newCastBoundingBox);
|
||||
|
||||
//If the new bounding box does not intersect with the old one, then update our bounding box reference
|
||||
if(!sameTarget)
|
||||
lastFishingBoundingBox = newCastBoundingBox;
|
||||
|
||||
return hasFished || sameTarget;
|
||||
}
|
||||
|
||||
public static BoundingBox makeBoundingBox(Vector centerOfCastVector) {
|
||||
return BoundingBox.of(centerOfCastVector, 2, 2, 2);
|
||||
}
|
||||
|
||||
public void setFishingTarget() {
|
||||
getPlayer().getTargetBlock(BlockUtils.getTransparentBlocks(), 100);
|
||||
}
|
||||
|
Reference in New Issue
Block a user