Archiviert
13
0

SPIGOT-1611: Make vehicles use the same speed checks as players

Dieser Commit ist enthalten in:
Thinkofdeath 2016-03-06 21:33:27 +00:00
Ursprung 935349e3a3
Commit 8ad0cd0895

Datei anzeigen

@ -173,7 +173,43 @@
}
public void a(PacketPlayInSteerVehicle packetplayinsteervehicle) {
@@ -229,6 +323,62 @@
@@ -191,7 +285,34 @@
double d9 = entity.motX * entity.motX + entity.motY * entity.motY + entity.motZ * entity.motZ;
double d10 = d6 * d6 + d7 * d7 + d8 * d8;
- if (d10 - d9 > 100.0D && (!this.minecraftServer.R() || !this.minecraftServer.Q().equals(entity.getName()))) {
+
+ // CraftBukkit start - handle custom speeds and skipped ticks
+ this.allowedPlayerTicks += (System.currentTimeMillis() / 50) - this.lastTick;
+ this.allowedPlayerTicks = Math.max(this.allowedPlayerTicks, 1);
+ this.lastTick = (int) (System.currentTimeMillis() / 50);
+
+ ++this.F;
+ int i = this.F - this.G; // PAIL: Rename
+ if (i > Math.max(this.allowedPlayerTicks, 5)) {
+ PlayerConnection.LOGGER.debug(this.player.getName() + " is sending move packets too frequently (" + i + " packets since last tick)");
+ i = 1;
+ }
+
+ if (d10 > 0) {
+ allowedPlayerTicks -= 1;
+ } else {
+ allowedPlayerTicks = 20;
+ }
+ float speed;
+ if (player.abilities.isFlying) {
+ speed = player.abilities.flySpeed * 20f;
+ } else {
+ speed = player.abilities.walkSpeed * 10f;
+ }
+ speed *= 2f; // TODO: Get the speed of the vehicle instead of the player
+
+ if (d10 - d9 > Math.pow((double) (10.0F * (float) i * speed), 2) && (!this.minecraftServer.R() || !this.minecraftServer.Q().equals(entity.getName()))) {
+ // CraftBukkit end
PlayerConnection.LOGGER.warn(entity.getName() + " (vehicle of " + this.player.getName() + ") moved too quickly! " + d6 + "," + d7 + "," + d8);
this.networkManager.sendPacket(new PacketPlayOutVehicleMove(entity));
return;
@@ -229,6 +350,62 @@
return;
}
@ -236,7 +272,7 @@
this.minecraftServer.getPlayerList().d(this.player);
this.player.checkMovement(this.player.locX - d0, this.player.locY - d1, this.player.locZ - d2);
this.D = d11 >= -0.03125D && !this.minecraftServer.getAllowFlight() && !worldserver.d(entity.getBoundingBox().g(0.0625D).a(0.0D, -0.55D, 0.0D));
@@ -273,13 +423,21 @@
@@ -273,13 +450,21 @@
this.A = this.e;
this.a(this.teleportPos.x, this.teleportPos.y, this.teleportPos.z, this.player.yaw, this.player.pitch);
}
@ -259,7 +295,7 @@
double d0 = this.player.locX;
double d1 = this.player.locY;
double d2 = this.player.locZ;
@@ -298,15 +456,32 @@
@@ -298,15 +483,33 @@
++this.F;
int i = this.F - this.G;
@ -291,10 +327,11 @@
- if (d11 - d10 > (double) (f2 * (float) i) && (!this.minecraftServer.R() || !this.minecraftServer.Q().equals(this.player.getName()))) {
+ if (d11 - d10 > Math.pow((double) (10.0F * (float) i * speed), 2) && (!this.minecraftServer.R() || !this.minecraftServer.Q().equals(this.player.getName()))) {
+ // CraftBukkit end
PlayerConnection.LOGGER.warn(this.player.getName() + " moved too quickly! " + d7 + "," + d8 + "," + d9);
this.a(this.player.locX, this.player.locY, this.player.locZ, this.player.yaw, this.player.pitch);
return;
@@ -352,6 +527,69 @@
@@ -352,6 +555,69 @@
}
}
@ -364,7 +401,7 @@
this.B = d12 >= -0.03125D;
this.B &= !this.minecraftServer.getAllowFlight() && !this.player.abilities.canFly;
this.B &= !this.player.hasEffect(MobEffects.LEVITATION) && !this.player.cB() && !worldserver.d(this.player.getBoundingBox().g(0.0625D).a(0.0D, -0.55D, 0.0D));
@@ -368,15 +606,79 @@
@@ -368,15 +634,79 @@
}
public void a(double d0, double d1, double d2, float f, float f1) {
@ -400,7 +437,8 @@
+ if (set.contains(PacketPlayOutPosition.EnumPlayerTeleportFlags.X_ROT)) {
+ pitch += from.getPitch();
+ }
+
- this.teleportPos = new Vec3D(d0 + d3, d1 + d4, d2 + d5);
+
+ Location to = new Location(this.getPlayer().getWorld(), x, y, z, yaw, pitch);
+ PlayerTeleportEvent event = new PlayerTeleportEvent(player, from.clone(), to.clone(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
@ -418,8 +456,7 @@
+
+ this.internalTeleport(d0, d1, d2, f, f1, set);
+ }
- this.teleportPos = new Vec3D(d0 + d3, d1 + d4, d2 + d5);
+
+ public void teleport(Location dest) {
+ internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.emptySet());
+ }
@ -449,7 +486,7 @@
float f2 = f;
float f3 = f1;
@@ -388,6 +690,14 @@
@@ -388,6 +718,14 @@
f3 = f1 + this.player.pitch;
}
@ -464,7 +501,7 @@
if (++this.teleportAwait == Integer.MAX_VALUE) {
this.teleportAwait = 0;
}
@@ -399,15 +709,32 @@
@@ -399,15 +737,32 @@
public void a(PacketPlayInBlockDig packetplayinblockdig) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockdig, this, this.player.x());
@ -498,7 +535,7 @@
itemstack = this.player.b(EnumHand.OFF_HAND);
this.player.a(EnumHand.OFF_HAND, this.player.b(EnumHand.MAIN_HAND));
this.player.a(EnumHand.MAIN_HAND, itemstack);
@@ -415,21 +742,21 @@
@@ -415,21 +770,21 @@
return;
@ -523,7 +560,7 @@
this.player.clearActiveItem();
itemstack = this.player.getItemInMainHand();
if (itemstack != null && itemstack.count == 0) {
@@ -438,8 +765,8 @@
@@ -438,8 +793,8 @@
return;
@ -534,7 +571,7 @@
case 7:
double d0 = this.player.locX - ((double) blockposition.getX() + 0.5D);
double d1 = this.player.locY - ((double) blockposition.getY() + 0.5D) + 1.5D;
@@ -455,7 +782,15 @@
@@ -455,7 +810,15 @@
if (!this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) {
this.player.playerInteractManager.a(blockposition, packetplayinblockdig.b());
} else {
@ -550,7 +587,7 @@
}
} else {
if (packetplayinblockdig.c() == PacketPlayInBlockDig.EnumPlayerDigType.STOP_DESTROY_BLOCK) {
@@ -475,10 +810,12 @@
@@ -475,10 +838,12 @@
default:
throw new IllegalArgumentException("Invalid player action");
}
@ -563,7 +600,7 @@
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
EnumHand enumhand = packetplayinuseitem.c();
ItemStack itemstack = this.player.b(enumhand);
@@ -492,6 +829,13 @@
@@ -492,6 +857,13 @@
chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage));
} else if (this.teleportPos == null && this.player.e((double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D) < 64.0D && !this.minecraftServer.a(worldserver, blockposition, this.player) && worldserver.getWorldBorder().a(blockposition)) {
@ -577,7 +614,7 @@
this.player.playerInteractManager.a(this.player, worldserver, itemstack, enumhand, blockposition, enumdirection, packetplayinuseitem.d(), packetplayinuseitem.e(), packetplayinuseitem.f());
}
@@ -507,19 +851,55 @@
@@ -507,19 +879,55 @@
public void a(PacketPlayInBlockPlace packetplayinblockplace) {
PlayerConnectionUtils.ensureMainThread(packetplayinblockplace, this, this.player.x());
@ -638,7 +675,7 @@
}
}
@@ -530,8 +910,8 @@
@@ -530,8 +938,8 @@
WorldServer[] aworldserver = this.minecraftServer.worldServer;
int i = aworldserver.length;
@ -649,7 +686,7 @@
if (worldserver != null) {
entity = packetplayinspectate.a(worldserver);
@@ -544,6 +924,8 @@
@@ -544,6 +952,8 @@
if (entity != null) {
this.player.setSpectatorTarget(this.player);
this.player.stopRiding();
@ -658,7 +695,7 @@
if (entity.world != this.player.world) {
WorldServer worldserver1 = this.player.x();
WorldServer worldserver2 = (WorldServer) entity.world;
@@ -569,12 +951,19 @@
@@ -569,12 +979,19 @@
} else {
this.player.enderTeleportTo(entity.locX, entity.locY, entity.locZ);
}
@ -679,7 +716,7 @@
public void a(PacketPlayInBoatMove packetplayinboatmove) {
PlayerConnectionUtils.ensureMainThread(packetplayinboatmove, this, this.player.x());
@@ -587,14 +976,29 @@
@@ -587,14 +1004,29 @@
}
public void a(IChatBaseComponent ichatbasecomponent) {
@ -711,7 +748,7 @@
if (this.minecraftServer.R() && this.player.getName().equals(this.minecraftServer.Q())) {
PlayerConnection.LOGGER.info("Stopping singleplayer server as player logged out");
this.minecraftServer.safeShutdown();
@@ -616,6 +1020,15 @@
@@ -616,6 +1048,15 @@
}
}
@ -727,7 +764,7 @@
try {
this.networkManager.sendPacket(packet);
} catch (Throwable throwable) {
@@ -637,17 +1050,32 @@
@@ -637,17 +1078,32 @@
public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
PlayerConnectionUtils.ensureMainThread(packetplayinhelditemslot, this, this.player.x());
@ -762,7 +799,7 @@
ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]);
chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
@@ -660,39 +1088,249 @@
@@ -660,39 +1116,249 @@
for (int i = 0; i < s.length(); ++i) {
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
@ -1020,7 +1057,7 @@
this.player.resetIdleTimer();
IJumpable ijumpable;
@@ -762,6 +1400,7 @@
@@ -762,6 +1428,7 @@
public void a(PacketPlayInUseEntity packetplayinuseentity) {
PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.x());
@ -1028,7 +1065,7 @@
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
Entity entity = packetplayinuseentity.a((World) worldserver);
@@ -778,22 +1417,72 @@
@@ -778,22 +1445,72 @@
EnumHand enumhand;
ItemStack itemstack;
@ -1102,7 +1139,7 @@
}
}
}
@@ -809,7 +1498,8 @@
@@ -809,7 +1526,8 @@
case 1:
if (this.player.viewingCredits) {
this.player.viewingCredits = false;
@ -1112,7 +1149,7 @@
} else {
if (this.player.getHealth() > 0.0F) {
return;
@@ -835,14 +1525,20 @@
@@ -835,14 +1553,20 @@
public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
PlayerConnectionUtils.ensureMainThread(packetplayinclosewindow, this, this.player.x());
@ -1134,7 +1171,7 @@
ArrayList arraylist = Lists.newArrayList();
for (int i = 0; i < this.player.activeContainer.c.size(); ++i) {
@@ -851,8 +1547,275 @@
@@ -851,8 +1575,275 @@
this.player.a(this.player.activeContainer, (List) arraylist);
} else {
@ -1341,10 +1378,10 @@
+ }
+ }
+ }
+
+ event.setCancelled(cancelled);
+ server.getPluginManager().callEvent(event);
+
+ switch (event.getResult()) {
+ case ALLOW:
+ case DEFAULT:
@ -1411,7 +1448,7 @@
if (ItemStack.matches(packetplayinwindowclick.e(), itemstack)) {
this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.a(), packetplayinwindowclick.d(), true));
this.player.f = true;
@@ -915,8 +1878,48 @@
@@ -915,8 +1906,48 @@
}
boolean flag1 = packetplayinsetcreativeslot.a() >= 1 && packetplayinsetcreativeslot.a() <= 45;
@ -1461,7 +1498,7 @@
if (flag1 && flag2 && flag3) {
if (itemstack == null) {
@@ -940,6 +1943,7 @@
@@ -940,6 +1971,7 @@
public void a(PacketPlayInTransaction packetplayintransaction) {
PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.x());
@ -1469,7 +1506,7 @@
Short oshort = (Short) this.k.get(this.player.activeContainer.windowId);
if (oshort != null && packetplayintransaction.b() == oshort.shortValue() && this.player.activeContainer.windowId == packetplayintransaction.a() && !this.player.activeContainer.c(this.player) && !this.player.isSpectator()) {
@@ -950,6 +1954,7 @@
@@ -950,6 +1982,7 @@
public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.x());
@ -1477,7 +1514,7 @@
this.player.resetIdleTimer();
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
BlockPosition blockposition = packetplayinupdatesign.a();
@@ -966,14 +1971,30 @@
@@ -966,14 +1999,30 @@
if (!tileentitysign.b() || tileentitysign.c() != this.player) {
this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign");
@ -1509,7 +1546,7 @@
tileentitysign.update();
worldserver.notify(blockposition, iblockdata, iblockdata, 3);
@@ -996,11 +2017,27 @@
@@ -996,11 +2045,27 @@
public void a(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.x());
@ -1538,7 +1575,7 @@
ArrayList arraylist = Lists.newArrayList();
Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b(), packetplayintabcomplete.c()).iterator();
@@ -1334,12 +2371,34 @@
@@ -1334,12 +2399,34 @@
packetdataserializer.release();
}
}