2014-08-18 15:43:17 +00:00
|
|
|
From df01fcb7e6f82f93930252373a4b6c1dc0f0b09b Mon Sep 17 00:00:00 2001
|
2014-07-21 20:46:54 +00:00
|
|
|
From: Thinkofdeath <thinkofdeath@spigotmc.org>
|
|
|
|
Date: Sun, 29 Jun 2014 21:10:34 +0100
|
|
|
|
Subject: [PATCH] Limit block placement/interaction packets
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
2014-08-18 15:43:17 +00:00
|
|
|
index 024ec84..bd61823 100644
|
2014-07-21 20:46:54 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
2014-07-25 03:21:57 +00:00
|
|
|
@@ -573,7 +573,20 @@ public class PlayerConnection implements PacketPlayInListener {
|
2014-07-21 20:46:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Spigot start - limit place/interactions
|
|
|
|
+ private long lastPlace = -1;
|
2014-07-25 03:21:57 +00:00
|
|
|
+ private int packets = 0;
|
2014-07-21 20:46:54 +00:00
|
|
|
+
|
|
|
|
public void a(PacketPlayInBlockPlace packetplayinblockplace) {
|
|
|
|
+ boolean throttled = false;
|
2014-07-25 03:21:57 +00:00
|
|
|
+ if (lastPlace != -1 && packetplayinblockplace.timestamp - lastPlace < 30 && packets++ >= 4) {
|
2014-07-21 20:46:54 +00:00
|
|
|
+ throttled = true;
|
2014-07-25 03:21:57 +00:00
|
|
|
+ } else if ( packetplayinblockplace.timestamp - lastPlace >= 30 || lastPlace == -1 )
|
2014-07-21 20:46:54 +00:00
|
|
|
+ {
|
|
|
|
+ lastPlace = packetplayinblockplace.timestamp;
|
2014-07-25 03:21:57 +00:00
|
|
|
+ packets = 0;
|
2014-07-21 20:46:54 +00:00
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
|
|
|
|
|
|
|
|
// CraftBukkit start
|
2014-07-25 03:21:57 +00:00
|
|
|
@@ -616,10 +629,14 @@ public class PlayerConnection implements PacketPlayInListener {
|
2014-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
// CraftBukkit start
|
|
|
|
int itemstackAmount = itemstack.count;
|
|
|
|
+ // Spigot start - skip the event if throttled
|
|
|
|
+ if (!throttled) {
|
|
|
|
org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack);
|
|
|
|
if (event.useItemInHand() != Event.Result.DENY) {
|
|
|
|
this.player.playerInteractManager.useItem(this.player, this.player.world, itemstack);
|
|
|
|
}
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
|
|
|
|
// CraftBukkit - notch decrements the counter by 1 in the above method with food,
|
|
|
|
// snowballs and so forth, but he does it in a place that doesn't cause the
|
2014-07-25 03:21:57 +00:00
|
|
|
@@ -640,7 +657,7 @@ public class PlayerConnection implements PacketPlayInListener {
|
2014-07-21 20:46:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (!this.player.playerInteractManager.interact(this.player, worldserver, itemstack, i, j, k, l, packetplayinblockplace.h(), packetplayinblockplace.i(), packetplayinblockplace.j())) {
|
|
|
|
+ if (throttled || !this.player.playerInteractManager.interact(this.player, worldserver, itemstack, i, j, k, l, packetplayinblockplace.h(), packetplayinblockplace.i(), packetplayinblockplace.j())) { // Spigot - skip the event if throttled
|
|
|
|
always = true; // force PacketPlayOutSetSlot to be sent to client to update ItemStack count
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
--
|
|
|
|
1.9.1
|
|
|
|
|