[BLIND] Review sprinting handling.

* Remove un-cancelling sprint events.
 * Use MovingData for sprinting time.
 * Change checking order in some places.
This commit is contained in:
asofold 2014-02-09 13:43:06 +01:00
parent 95420740ee
commit ad2105bdfb
2 changed files with 18 additions and 24 deletions

View File

@ -83,13 +83,13 @@ public class CombinedListener extends CheckListener {
* @param event * @param event
* the event * the event
*/ */
@EventHandler( @EventHandler(priority = EventPriority.MONITOR) // HIGHEST)
priority = EventPriority.HIGHEST)
public void onPlayerToggleSprintHighest(final PlayerToggleSprintEvent event) { public void onPlayerToggleSprintHighest(final PlayerToggleSprintEvent event) {
// Some plugins cancel "sprinting", which makes no sense at all because it doesn't stop people from sprinting // // TODO: Check the un-cancelling.
// and rewards them by reducing their hunger bar as if they were walking instead of sprinting. // // Some plugins cancel "sprinting", which makes no sense at all because it doesn't stop people from sprinting
if (event.isCancelled() && event.isSprinting()) // // and rewards them by reducing their hunger bar as if they were walking instead of sprinting.
event.setCancelled(false); // if (event.isCancelled() && event.isSprinting())
// event.setCancelled(false);
// Feed the improbable. // Feed the improbable.
Improbable.feed(event.getPlayer(), 0.35f, System.currentTimeMillis()); Improbable.feed(event.getPlayer(), 0.35f, System.currentTimeMillis());
} }

View File

@ -227,22 +227,22 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
// data.lastAttackedDist = targetDist; // data.lastAttackedDist = targetDist;
// Care for the "lost sprint problem": sprint resets, client moves as if still... // Care for the "lost sprint problem": sprint resets, client moves as if still...
if (!cancelled && player.isSprinting() && TrigUtil.distance(loc.getX(), loc.getZ(), targetLoc.getX(), targetLoc.getZ()) < 4.5){ // TODO: Use stored distance calculation same as reach check?
// TODO: Reduce distance by width of other entity [make an auxiliary method, use same value for reach]. // TODO: For pvp: make use of "player was there" heuristic later on.
// TODO: For pvp: make use of "player was there" heuristic later on. // TODO: Confine further with simple pre-conditions.
if (!cancelled && TrigUtil.distance(loc.getX(), loc.getZ(), targetLoc.getX(), targetLoc.getZ()) < 4.5){
final MovingData mData = MovingData.getData(player); final MovingData mData = MovingData.getData(player);
// Check if fly checks is an issue at all, re-check "real sprinting".
if (mData.fromX != Double.MAX_VALUE && mData.mediumLiftOff != MediumLiftOff.LIMIT_JUMP){ if (mData.fromX != Double.MAX_VALUE && mData.mediumLiftOff != MediumLiftOff.LIMIT_JUMP){
// TODO: What would mData.lostSprintCount > 0 mean here?
// TODO: Confine further.
final double hDist = TrigUtil.distance(loc.getX(), loc.getZ(), mData.fromX, mData.fromZ); final double hDist = TrigUtil.distance(loc.getX(), loc.getZ(), mData.fromX, mData.fromZ);
if (hDist >= 0.23) { if (hDist >= 0.23) {
// TODO: Might need to check hDist relative to speed / modifiers. // TODO: Might need to check hDist relative to speed / modifiers.
final MovingConfig mc = MovingConfig.getConfig(player); final MovingConfig mc = MovingConfig.getConfig(player);
// Check if fly checks is an issue at all, re-check "real sprinting".
if (now <= mData.timeSprinting + mc.sprintingGrace && MovingListener.shouldCheckSurvivalFly(player, mData, mc)){ if (now <= mData.timeSprinting + mc.sprintingGrace && MovingListener.shouldCheckSurvivalFly(player, mData, mc)){
// Judge as "lost sprint" problem. // Judge as "lost sprint" problem.
// TODO: What would mData.lostSprintCount > 0 mean here?
mData.lostSprintCount = 7; mData.lostSprintCount = 7;
if (cc.debug && BuildParameters.debugLevel > 0){ if ((cc.debug || mc.debug) && BuildParameters.debugLevel > 0){
System.out.println(player.getName() + " (lostsprint) hDist to last from: " + hDist + " | targetdist=" + TrigUtil.distance(loc.getX(), loc.getZ(), targetLoc.getX(), targetLoc.getZ()) + " | sprinting=" + player.isSprinting() + " | food=" + player.getFoodLevel() +" | hbuf=" + mData.sfHorizontalBuffer); System.out.println(player.getName() + " (lostsprint) hDist to last from: " + hDist + " | targetdist=" + TrigUtil.distance(loc.getX(), loc.getZ(), targetLoc.getX(), targetLoc.getZ()) + " | sprinting=" + player.isSprinting() + " | food=" + player.getFoodLevel() +" | hbuf=" + mData.sfHorizontalBuffer);
} }
} }
@ -432,15 +432,9 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
*/ */
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerToggleSprint(final PlayerToggleSprintEvent event) { public void onPlayerToggleSprint(final PlayerToggleSprintEvent event) {
/* if (event.isSprinting()) {
* ____ _ _____ _ ____ _ _ FightData.getData(event.getPlayer()).knockbackSprintTime = System.currentTimeMillis();
* | _ \| | __ _ _ _ ___ _ __ |_ _|__ __ _ __ _| | ___ / ___| _ __ _ __(_)_ __ | |_ }
* | |_) | |/ _` | | | |/ _ \ '__| | |/ _ \ / _` |/ _` | |/ _ \ \___ \| '_ \| '__| | '_ \| __|
* | __/| | (_| | |_| | __/ | | | (_) | (_| | (_| | | __/ ___) | |_) | | | | | | | |_
* |_| |_|\__,_|\__, |\___|_| |_|\___/ \__, |\__, |_|\___| |____/| .__/|_| |_|_| |_|\__|
* |___/ |___/ |___/ |_|
*/
if (event.isSprinting()) FightData.getData(event.getPlayer()).knockbackSprintTime = System.currentTimeMillis();
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
@ -448,10 +442,10 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
final Entity entity = event.getEntity(); final Entity entity = event.getEntity();
if (!(entity instanceof Player)) return; if (!(entity instanceof Player)) return;
final Player player = (Player) entity; final Player player = (Player) entity;
if (event.getRegainReason() != RegainReason.SATIATED){ if (event.getRegainReason() != RegainReason.SATIATED) {
return; return;
} }
if (fastHeal.isEnabled(player) && fastHeal.check(player)){ if (fastHeal.isEnabled(player) && fastHeal.check(player)) {
// TODO: Can clients force events with 0-re-gain ? // TODO: Can clients force events with 0-re-gain ?
event.setCancelled(true); event.setCancelled(true);
} }