Skip to content

Commit

Permalink
Add Player::setCheckMovement(boolean)
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Oct 10, 2016
1 parent 490be8c commit 069f7a2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
6 changes: 0 additions & 6 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
<artifactId>leveldb</artifactId>
<version>0.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
Expand Down
17 changes: 12 additions & 5 deletions server/src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import cn.nukkit.utils.Binary;
import cn.nukkit.utils.TextFormat;
import cn.nukkit.utils.Zlib;

import java.io.IOException;
import java.nio.ByteOrder;
import java.util.*;
Expand Down Expand Up @@ -179,6 +180,8 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde

protected AdventureSettings adventureSettings;

protected boolean checkMovement = true;

private final Map<Integer, Boolean> needACK = new HashMap<>();

private Map<Integer, List<DataPacket>> batchedPackets = new TreeMap<>();
Expand Down Expand Up @@ -1246,7 +1249,7 @@ protected void processMovement(int tickDiff) {

double diff = (diffX * diffX + diffY * diffY + diffZ * diffZ) / ((double) (tickDiff * tickDiff));

if (!server.getAllowFlight() && this.isSurvival()) {
if (this.checkMovement && !server.getAllowFlight() && this.isSurvival()) {
if (!this.isSleeping()) {
if (diff > 0.125) {
PlayerInvalidMoveEvent ev;
Expand Down Expand Up @@ -1280,7 +1283,7 @@ protected void processMovement(int tickDiff) {
this.level);
Location to = this.getLocation();

if (!revert && (Math.pow(this.lastX - to.x, 2) + Math.pow(this.lastY - to.y, 2) + Math.pow(this.lastZ - to.z, 2)) > (1/16) || (Math.abs(this.lastYaw - to.yaw) + Math.abs(this.lastPitch - to.pitch)) > 10) {
if (!revert && (Math.pow(this.lastX - to.x, 2) + Math.pow(this.lastY - to.y, 2) + Math.pow(this.lastZ - to.z, 2)) > (1d / 16d) || (Math.abs(this.lastYaw - to.yaw) + Math.abs(this.lastPitch - to.pitch)) > 10) {
boolean isFirst = this.firstMove;

this.firstMove = false;
Expand Down Expand Up @@ -1570,13 +1573,13 @@ protected void processLogin() {
this.playedBefore = (nbt.getLong("lastPlayed") - nbt.getLong("firstPlayed")) > 1;

boolean alive = true;

nbt.putString("NameTag", this.username);

if (0 >= nbt.getShort("Health")) {
alive = false;
alive = false;
}

int exp = nbt.getInt("EXP");
int expLevel = nbt.getInt("expLevel");
this.setExperience(exp, expLevel);
Expand Down Expand Up @@ -4041,6 +4044,10 @@ public void setDimension() {
this.dataPacket(pk);
}

public void setCheckMovement(boolean checkMovement) {
this.checkMovement = checkMovement;
}

public synchronized void setLocale(Locale locale) {
this.locale.set(locale);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* call when a player moves wrongly
*
* @author WilliamGao
* @version 0.1 (23/11/2015)
*/

public class PlayerInvalidMoveEvent extends PlayerEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();
Expand All @@ -29,6 +29,10 @@ public boolean isRevert() {
return this.revert;
}

/**
* @deprecated If you just simply want to disable the movement check, please use {@link Player#setCheckMovement(boolean)} instead.
*/
@Deprecated
public void setRevert(boolean revert) {
this.revert = revert;
}
Expand Down

0 comments on commit 069f7a2

Please sign in to comment.