mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 07:06:45 +01:00
Less aggressive detection
This commit is contained in:
parent
2d849f55e5
commit
bb118607ce
@ -37,6 +37,7 @@ import org.bukkit.entity.*;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
@ -322,11 +323,16 @@ public class PlayerListener implements Listener {
|
|||||||
Entity caught = event.getCaught();
|
Entity caught = event.getCaught();
|
||||||
FishingManager fishingManager = UserManager.getPlayer(player).getFishingManager();
|
FishingManager fishingManager = UserManager.getPlayer(player).getFishingManager();
|
||||||
|
|
||||||
//Fishing Too Often
|
//Track the hook
|
||||||
if(event.getState() != PlayerFishEvent.State.CAUGHT_ENTITY && fishingManager.isFishingTooOften())
|
if(event.getHook().getMetadata(mcMMO.FISH_HOOK_REF_METAKEY).size() == 0)
|
||||||
|
{
|
||||||
|
fishingManager.setFishHookReference(event.getHook());
|
||||||
|
}
|
||||||
|
|
||||||
|
//Spam Fishing
|
||||||
|
if(event.getState() == PlayerFishEvent.State.CAUGHT_FISH && fishingManager.isFishingTooOften())
|
||||||
{
|
{
|
||||||
event.setExpToDrop(0);
|
event.setExpToDrop(0);
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
if(caught instanceof Item)
|
if(caught instanceof Item)
|
||||||
{
|
{
|
||||||
@ -348,7 +354,6 @@ public class PlayerListener implements Listener {
|
|||||||
if(fishingManager.isExploitingFishing(event.getHook().getLocation().toVector()))
|
if(fishingManager.isExploitingFishing(event.getHook().getLocation().toVector()))
|
||||||
{
|
{
|
||||||
event.setExpToDrop(0);
|
event.setExpToDrop(0);
|
||||||
event.setCancelled(true);
|
|
||||||
Item caughtItem = (Item) caught;
|
Item caughtItem = (Item) caught;
|
||||||
caughtItem.remove();
|
caughtItem.remove();
|
||||||
return;
|
return;
|
||||||
@ -356,6 +361,7 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
fishingManager.handleFishing((Item) caught);
|
fishingManager.handleFishing((Item) caught);
|
||||||
fishingManager.setFishingTarget();
|
fishingManager.setFishingTarget();
|
||||||
|
//fishingManager.setFishHookReference(null);
|
||||||
return;
|
return;
|
||||||
case CAUGHT_ENTITY:
|
case CAUGHT_ENTITY:
|
||||||
if (fishingManager.canShake(caught)) {
|
if (fishingManager.canShake(caught)) {
|
||||||
@ -631,6 +637,15 @@ public class PlayerListener implements Listener {
|
|||||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
|
||||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||||
|
|
||||||
|
//Spam Fishing Detection
|
||||||
|
if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)
|
||||||
|
{
|
||||||
|
if(heldItem.getType() == Material.FISHING_ROD || player.getInventory().getItemInOffHand().getType() == Material.FISHING_ROD)
|
||||||
|
{
|
||||||
|
mcMMOPlayer.getFishingManager().setFishingRodCastTimestamp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case RIGHT_CLICK_BLOCK:
|
case RIGHT_CLICK_BLOCK:
|
||||||
if(player.getInventory().getItemInOffHand().getType() != Material.AIR && !player.isInsideVehicle() && !player.isSneaking()) {
|
if(player.getInventory().getItemInOffHand().getType() != Material.AIR && !player.isInsideVehicle() && !player.isSneaking()) {
|
||||||
|
@ -96,6 +96,7 @@ public class mcMMO extends JavaPlugin {
|
|||||||
private static boolean isRetroModeEnabled;
|
private static boolean isRetroModeEnabled;
|
||||||
|
|
||||||
/* Metadata Values */
|
/* Metadata Values */
|
||||||
|
public static final String FISH_HOOK_REF_METAKEY = "mcMMO: Fish Hook Tracker";
|
||||||
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
|
public final static String entityMetadataKey = "mcMMO: Spawned Entity";
|
||||||
public final static String blockMetadataKey = "mcMMO: Piston Tracking";
|
public final static String blockMetadataKey = "mcMMO: Piston Tracking";
|
||||||
public final static String furnaceMetadataKey = "mcMMO: Tracked Furnace";
|
public final static String furnaceMetadataKey = "mcMMO: Tracked Furnace";
|
||||||
|
@ -16,6 +16,7 @@ import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
|
|||||||
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerFishingTreasureEvent;
|
||||||
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
|
import com.gmail.nossr50.events.skills.fishing.McMMOPlayerShakeEvent;
|
||||||
import com.gmail.nossr50.locale.LocaleLoader;
|
import com.gmail.nossr50.locale.LocaleLoader;
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
import com.gmail.nossr50.skills.SkillManager;
|
import com.gmail.nossr50.skills.SkillManager;
|
||||||
import com.gmail.nossr50.util.*;
|
import com.gmail.nossr50.util.*;
|
||||||
import com.gmail.nossr50.util.player.NotificationManager;
|
import com.gmail.nossr50.util.player.NotificationManager;
|
||||||
@ -43,8 +44,10 @@ import java.util.*;
|
|||||||
public class FishingManager extends SkillManager {
|
public class FishingManager extends SkillManager {
|
||||||
private final long FISHING_COOLDOWN_SECONDS = 1000L;
|
private final long FISHING_COOLDOWN_SECONDS = 1000L;
|
||||||
|
|
||||||
private long fishingTimestamp = 0L;
|
private long fishingRodCastTimestamp = 0L;
|
||||||
|
private long fishHookSpawnTimestamp = 0L;
|
||||||
private long lastWarned = 0L;
|
private long lastWarned = 0L;
|
||||||
|
private FishHook fishHookReference;
|
||||||
private BoundingBox lastFishingBoundingBox;
|
private BoundingBox lastFishingBoundingBox;
|
||||||
private Item fishingCatch;
|
private Item fishingCatch;
|
||||||
private Location hookLocation;
|
private Location hookLocation;
|
||||||
@ -61,19 +64,48 @@ public class FishingManager extends SkillManager {
|
|||||||
return getSkillLevel() >= RankUtils.getUnlockLevel(SubSkillType.FISHING_MASTER_ANGLER) && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.FISHING_MASTER_ANGLER);
|
return getSkillLevel() >= RankUtils.getUnlockLevel(SubSkillType.FISHING_MASTER_ANGLER) && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.FISHING_MASTER_ANGLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFishingRodCastTimestamp()
|
||||||
|
{
|
||||||
|
//Only track spam casting if the fishing hook is fresh
|
||||||
|
if(System.currentTimeMillis() > fishHookSpawnTimestamp + 500)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(System.currentTimeMillis() < fishingRodCastTimestamp + 300)
|
||||||
|
{
|
||||||
|
getPlayer().setFoodLevel(Math.min(getPlayer().getFoodLevel() - 1, 0));
|
||||||
|
getPlayer().getInventory().getItemInMainHand().setDurability((short) (getPlayer().getInventory().getItemInMainHand().getDurability() + 5));
|
||||||
|
getPlayer().updateInventory();
|
||||||
|
getPlayer().sendMessage(LocaleLoader.getString("Fishing.Exhausting"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fishingRodCastTimestamp = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFishHookReference(FishHook fishHook)
|
||||||
|
{
|
||||||
|
if(fishHook.getMetadata(mcMMO.FISH_HOOK_REF_METAKEY).size() > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fishHook.setMetadata(mcMMO.FISH_HOOK_REF_METAKEY, mcMMO.metadataValue);
|
||||||
|
this.fishHookReference = fishHook;
|
||||||
|
fishHookSpawnTimestamp = System.currentTimeMillis();
|
||||||
|
fishingRodCastTimestamp = System.currentTimeMillis();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFishingTooOften()
|
public boolean isFishingTooOften()
|
||||||
{
|
{
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
boolean hasFished = (currentTime < fishingTimestamp + (FISHING_COOLDOWN_SECONDS * 10));
|
long fishHookSpawnCD = fishHookSpawnTimestamp + 1000;
|
||||||
|
boolean hasFished = (currentTime < fishHookSpawnCD);
|
||||||
|
|
||||||
if(hasFished && lastWarned + (1000 * 5) < System.currentTimeMillis())
|
if(hasFished && (lastWarned + (1000 * 1) < currentTime))
|
||||||
{
|
{
|
||||||
getPlayer().sendMessage(LocaleLoader.getString("Fishing.Scared"));
|
getPlayer().sendMessage(LocaleLoader.getString("Fishing.Scared"));
|
||||||
lastWarned = System.currentTimeMillis();
|
lastWarned = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
fishingTimestamp = currentTime;
|
|
||||||
|
|
||||||
return hasFished;
|
return hasFished;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,12 +117,9 @@ public class FishingManager extends SkillManager {
|
|||||||
return false;
|
return false;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
if(lastFishingBoundingBox == null)
|
|
||||||
lastFishingBoundingBox = makeBoundingBox(centerOfCastVector);
|
|
||||||
|
|
||||||
BoundingBox newCastBoundingBox = makeBoundingBox(centerOfCastVector);
|
BoundingBox newCastBoundingBox = makeBoundingBox(centerOfCastVector);
|
||||||
|
|
||||||
boolean sameTarget = lastFishingBoundingBox.overlaps(newCastBoundingBox);
|
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 the new bounding box does not intersect with the old one, then update our bounding box reference
|
||||||
if(!sameTarget)
|
if(!sameTarget)
|
||||||
|
@ -219,6 +219,7 @@ Excavation.Skills.GigaDrillBreaker.Other.On=[[GREEN]]{0}[[DARK_GREEN]] has used
|
|||||||
#FISHING
|
#FISHING
|
||||||
Fishing.Scarcity=[[YELLOW]]&oThis area is suffering from overfishing, try fishing in a new area.
|
Fishing.Scarcity=[[YELLOW]]&oThis area is suffering from overfishing, try fishing in a new area.
|
||||||
Fishing.Scared=[[GRAY]]&oChaotic movements will scare fish!
|
Fishing.Scared=[[GRAY]]&oChaotic movements will scare fish!
|
||||||
|
Fishing.Exhausting=[[RED]]&oImproper use of the fishing rod will cause fatigue and wear out the rod!
|
||||||
Fishing.Ability.Info=Magic Hunter: [[GRAY]] **Improves With Treasure Hunter Rank**
|
Fishing.Ability.Info=Magic Hunter: [[GRAY]] **Improves With Treasure Hunter Rank**
|
||||||
Fishing.Ability.Locked.0=LOCKED UNTIL {0}+ SKILL (SHAKE)
|
Fishing.Ability.Locked.0=LOCKED UNTIL {0}+ SKILL (SHAKE)
|
||||||
Fishing.Ability.Locked.1=LOCKED UNTIL {0}+ SKILL (ICE FISHING)
|
Fishing.Ability.Locked.1=LOCKED UNTIL {0}+ SKILL (ICE FISHING)
|
||||||
|
Loading…
Reference in New Issue
Block a user