Moved same target to class variable

This commit is contained in:
smuddgge 2023-01-20 19:58:07 +00:00
parent c4f890d00e
commit e1e352656e
2 changed files with 11 additions and 11 deletions

View File

@ -452,7 +452,7 @@ public class PlayerListener implements Listener {
if(ExperienceConfig.getInstance().isFishingExploitingPrevented()) { if(ExperienceConfig.getInstance().isFishingExploitingPrevented()) {
fishingManager.processExploiting(event.getHook().getLocation().toVector()); fishingManager.processExploiting(event.getHook().getLocation().toVector());
if (fishingManager.isExploitingFishing(event.getHook().getLocation().toVector())) { if (fishingManager.isExploitingFishing(event.getHook().getLocation().toVector())) {
player.sendMessage(LocaleLoader.getString("Fishing.ScarcityTip", ExperienceConfig.getInstance().getFishingExploitingOptionMoveRange())); player.sendMessage(LocaleLoader.getString("Fishing.ScarcityTip", ExperienceConfig.getInstance().getFishingExploitingOptionMoveRange()));
event.setExpToDrop(0); event.setExpToDrop(0);

View File

@ -51,6 +51,7 @@ public class FishingManager extends SkillManager {
private long lastWarnedExhaust = 0L; private long lastWarnedExhaust = 0L;
private FishHook fishHookReference; private FishHook fishHookReference;
private BoundingBox lastFishingBoundingBox; private BoundingBox lastFishingBoundingBox;
private boolean sameTarget;
private Item fishingCatch; private Item fishingCatch;
private Location hookLocation; private Location hookLocation;
private int fishCaughtCounter = 1; private int fishCaughtCounter = 1;
@ -127,12 +128,17 @@ public class FishingManager extends SkillManager {
public void processExploiting(Vector centerOfCastVector) { public void processExploiting(Vector centerOfCastVector) {
BoundingBox newCastBoundingBox = makeBoundingBox(centerOfCastVector); BoundingBox newCastBoundingBox = makeBoundingBox(centerOfCastVector);
boolean sameTarget = lastFishingBoundingBox != null && lastFishingBoundingBox.overlaps(newCastBoundingBox); this.sameTarget = lastFishingBoundingBox != null && lastFishingBoundingBox.overlaps(newCastBoundingBox);
if (sameTarget) if (this.sameTarget) {
fishCaughtCounter++; fishCaughtCounter++;
else }
else {
fishCaughtCounter = 1; fishCaughtCounter = 1;
}
//If the new bounding box does not intersect with the old one, then update our bounding box reference
if (!this.sameTarget) lastFishingBoundingBox = newCastBoundingBox;
if (fishCaughtCounter + 1 == ExperienceConfig.getInstance().getFishingExploitingOptionOverFishLimit()) { if (fishCaughtCounter + 1 == ExperienceConfig.getInstance().getFishingExploitingOptionOverFishLimit()) {
getPlayer().sendMessage(LocaleLoader.getString("Fishing.LowResourcesTip", ExperienceConfig.getInstance().getFishingExploitingOptionMoveRange())); getPlayer().sendMessage(LocaleLoader.getString("Fishing.LowResourcesTip", ExperienceConfig.getInstance().getFishingExploitingOptionMoveRange()));
@ -147,13 +153,7 @@ public class FishingManager extends SkillManager {
return false; return false;
}*/ }*/
BoundingBox newCastBoundingBox = makeBoundingBox(centerOfCastVector); return this.sameTarget && fishCaughtCounter >= ExperienceConfig.getInstance().getFishingExploitingOptionOverFishLimit();
boolean sameTarget = lastFishingBoundingBox != null && 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 sameTarget && fishCaughtCounter >= ExperienceConfig.getInstance().getFishingExploitingOptionOverFishLimit();
} }
public static BoundingBox makeBoundingBox(Vector centerOfCastVector) { public static BoundingBox makeBoundingBox(Vector centerOfCastVector) {