Further adjustments to Improbable (feed).

Just feed weights to improbable instead of checking for some places,
getting rid of some unnecessary violations cascading. Also feed for
fighting speed violations.
This commit is contained in:
asofold 2012-12-29 22:10:45 +01:00
parent 05c7699937
commit f4680da0d4
6 changed files with 31 additions and 24 deletions

View File

@ -108,14 +108,11 @@ public class BlockPlaceListener extends CheckListener {
if (fastPlace.check(player, block)) if (fastPlace.check(player, block))
cancelled = true; cancelled = true;
else{ else{
// Combined speed. // Feed the improbable.
if (Improbable.check(player, 0.5f, System.currentTimeMillis())){ Improbable.feed(player, 0.5f, System.currentTimeMillis());
cancelled = true;
} }
} }
}
// Second, the no swing check (player doesn't swing his arm when placing a lily pad). // Second, the no swing check (player doesn't swing his arm when placing a lily pad).
if (!cancelled && mat != Material.WATER_LILY && noSwing.isEnabled(player) if (!cancelled && mat != Material.WATER_LILY && noSwing.isEnabled(player)
&& noSwing.check(player)) && noSwing.check(player))

View File

@ -74,12 +74,6 @@ public class CombinedListener extends CheckListener {
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(priority=EventPriority.LOW)
public void onPlayerToggleSprint(final PlayerToggleSprintEvent event){
// Check also in case of cancelled events.
if (Improbable.check(event.getPlayer(), 0.35f, System.currentTimeMillis())) event.setCancelled(true);
}
/** /**
* A workaround for cancelled PlayerToggleSprintEvents. * A workaround for cancelled PlayerToggleSprintEvents.
* *
@ -93,13 +87,15 @@ public class CombinedListener extends CheckListener {
// and rewards them by reducing their hunger bar as if they were walking instead of sprinting. // and rewards them by reducing their hunger bar as if they were walking instead of sprinting.
if (event.isCancelled() && event.isSprinting()) if (event.isCancelled() && event.isSprinting())
event.setCancelled(false); event.setCancelled(false);
// Feed the improbable.
Improbable.feed(event.getPlayer(), 0.35f, System.currentTimeMillis());
} }
@EventHandler(priority=EventPriority.LOW) @EventHandler(priority=EventPriority.MONITOR)
public void onPlayerToggleSneak(final PlayerToggleSneakEvent event){ public void onPlayerToggleSneak(final PlayerToggleSneakEvent event){
// Check also in case of cancelled events. // Check also in case of cancelled events.
// TODO: Maybe this is not good to cancel. // Feed the improbable.
if (Improbable.check(event.getPlayer(), 0.35f, System.currentTimeMillis())) event.setCancelled(true); Improbable.feed(event.getPlayer(), 0.35f, System.currentTimeMillis());
} }
@EventHandler(priority=EventPriority.LOWEST) @EventHandler(priority=EventPriority.LOWEST)

View File

@ -27,6 +27,16 @@ public class Improbable extends Check {
return instance.checkImprobable(player, weight, now); return instance.checkImprobable(player, weight, now);
} }
/**
* Feed the check but no violations processing (convenience method).
* @param player
* @param weight
* @param now
*/
public static final void feed(final Player player, final float weight, final long now){
CombinedData.getData(player).improbableCount.add(now, weight);
}
//////////////////////////////////// ////////////////////////////////////
// Instance methods. // Instance methods.
/////////////////////////////////// ///////////////////////////////////

View File

@ -110,12 +110,17 @@ public class FightListener extends CheckListener {
// Run through the main checks. // Run through the main checks.
if (!cancelled && speed.isEnabled(player)){ if (!cancelled && speed.isEnabled(player)){
if (speed.check(player, now)) if (speed.check(player, now)){
cancelled = true; cancelled = true;
// Combined speed: // Still feed the improbable.
else if (Improbable.check(player, 1f, now)) Improbable.feed(player, 1f, now);
}
else if (Improbable.check(player, 1f, now)){
// Feed improbable in case of ok-moves too.
// TODO: consider only feeding if attacking with higher average speed (!)
cancelled = true; cancelled = true;
} }
}
if (angle.isEnabled(player)) { if (angle.isEnabled(player)) {
// The "fast turning" checks are checked in any case because they accumulate data. // The "fast turning" checks are checked in any case because they accumulate data.

View File

@ -116,9 +116,10 @@ public class Reach extends Check {
data.reachLastViolationTime = System.currentTimeMillis(); data.reachLastViolationTime = System.currentTimeMillis();
} }
else if (lenpRel - distanceLimit * reachMod > 0){ else if (lenpRel - distanceLimit * reachMod > 0){
// Silent cancel.
data.reachLastViolationTime = Math.max(data.reachLastViolationTime, System.currentTimeMillis() - cc.reachPenalty / 2); data.reachLastViolationTime = Math.max(data.reachLastViolationTime, System.currentTimeMillis() - cc.reachPenalty / 2);
cancel = true; cancel = true;
Improbable.check(player, (float) (lenpRel - distanceLimit * reachMod) / 2f, System.currentTimeMillis()); Improbable.feed(player, (float) (lenpRel - distanceLimit * reachMod) / 2f, System.currentTimeMillis());
} }
else{ else{
// Player passed the check, reward him. // Player passed the check, reward him.

View File

@ -172,10 +172,8 @@ public class InventoryListener extends CheckListener {
// The check requested the event to be cancelled. // The check requested the event to be cancelled.
event.setCancelled(true); event.setCancelled(true);
} }
else if (Improbable.check(player, 0.7f, System.currentTimeMillis())){ // Feed the improbable.
// Combined speed: Improbable.feed(player, 0.7f, System.currentTimeMillis());
// event.setCancelled(true);
}
} }
} }
} }