3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 04:20:08 +01:00

Filter extra right click air interaction events

Dieser Commit ist enthalten in:
Thinkofdeath 2014-12-07 11:04:22 +00:00
Ursprung 1227934d57
Commit 7711956f44

Datei anzeigen

@ -1,5 +1,5 @@
--- ../work/decompile-8eb82bde//net/minecraft/server/PlayerConnection.java 2014-12-06 20:53:31.195313494 +0000
+++ src/main/java/net/minecraft/server/PlayerConnection.java 2014-12-06 20:50:54.967316961 +0000
--- ../work/decompile-8eb82bde//net/minecraft/server/PlayerConnection.java 2014-12-07 11:03:59.465024903 +0000
+++ src/main/java/net/minecraft/server/PlayerConnection.java 2014-12-07 11:03:41.193025101 +0000
@@ -16,6 +16,48 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -390,15 +390,37 @@
ItemStack itemstack = this.player.inventory.getItemInHand();
boolean flag = false;
BlockPosition blockposition = packetplayinblockplace.a();
@@ -390,7 +627,18 @@
@@ -390,7 +627,40 @@
return;
}
- this.player.playerInteractManager.useItem(this.player, worldserver, itemstack);
+ // CraftBukkit start
+ int itemstackAmount = itemstack.count;
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack);
+ if (event.useItemInHand() != Event.Result.DENY) {
+
+ // Raytrace to look for 'rogue armswings'
+ float f1 = this.player.pitch;
+ float f2 = this.player.yaw;
+ double d0 = this.player.locX;
+ double d1 = this.player.locY + (double) this.player.getHeadHeight();
+ double d2 = this.player.locZ;
+ Vec3D vec3d = new Vec3D(d0, d1, d2);
+
+ float f3 = MathHelper.cos(-f2 * 0.017453292F - 3.1415927F);
+ float f4 = MathHelper.sin(-f2 * 0.017453292F - 3.1415927F);
+ float f5 = -MathHelper.cos(-f1 * 0.017453292F);
+ float f6 = MathHelper.sin(-f1 * 0.017453292F);
+ float f7 = f4 * f5;
+ float f8 = f3 * f5;
+ double d3 = player.playerInteractManager.getGameMode() == EnumGamemode.CREATIVE ? 5.0D : 4.5D;
+ Vec3D vec3d1 = vec3d.add((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
+ MovingObjectPosition movingobjectposition = this.player.world.rayTrace(vec3d, vec3d1, false);
+
+ org.bukkit.event.player.PlayerInteractEvent event = null;
+ if (movingobjectposition == null || movingobjectposition.type != EnumMovingObjectType.BLOCK) {
+ event = CraftEventFactory.callPlayerInteractEvent(this.player, Action.RIGHT_CLICK_AIR, itemstack);
+ }
+ if (event == null || event.useItemInHand() != Event.Result.DENY) {
+ this.player.playerInteractManager.useItem(this.player, this.player.world, itemstack);
+ }
+
@ -410,7 +432,7 @@
} else if (blockposition.getY() >= this.minecraftServer.getMaxBuildHeight() - 1 && (enumdirection == EnumDirection.UP || blockposition.getY() >= this.minecraftServer.getMaxBuildHeight())) {
ChatMessage chatmessage = new ChatMessage("build.tooHigh", new Object[] { Integer.valueOf(this.minecraftServer.getMaxBuildHeight())});
@@ -398,9 +646,21 @@
@@ -398,9 +668,21 @@
this.player.playerConnection.sendPacket(new PacketPlayOutChat(chatmessage));
flag = true;
} else {
@ -433,7 +455,7 @@
flag = true;
}
@@ -423,7 +683,8 @@
@@ -423,7 +705,8 @@
this.player.activeContainer.b();
this.player.g = false;
@ -443,7 +465,7 @@
this.sendPacket(new PacketPlayOutSetSlot(this.player.activeContainer.windowId, slot.rawSlotIndex, this.player.inventory.getItemInHand()));
}
}
@@ -437,8 +698,8 @@
@@ -437,8 +720,8 @@
WorldServer[] aworldserver = this.minecraftServer.worldServer;
int i = aworldserver.length;
@ -454,7 +476,7 @@
if (worldserver != null) {
entity = packetplayinspectate.a(worldserver);
@@ -455,6 +716,7 @@
@@ -455,6 +738,7 @@
WorldServer worldserver1 = this.player.u();
WorldServer worldserver2 = (WorldServer) entity.world;
@ -462,7 +484,7 @@
this.player.dimension = entity.dimension;
this.sendPacket(new PacketPlayOutRespawn(this.player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldData().getType(), this.player.playerInteractManager.getGameMode()));
worldserver1.removeEntity(this.player);
@@ -472,6 +734,9 @@
@@ -472,6 +756,9 @@
this.player.playerInteractManager.a(worldserver2);
this.minecraftServer.getPlayerList().b(this.player, worldserver2);
this.minecraftServer.getPlayerList().updateClient(this.player);
@ -472,7 +494,7 @@
} else {
this.player.enderTeleportTo(entity.locX, entity.locY, entity.locZ);
}
@@ -483,14 +748,29 @@
@@ -483,14 +770,29 @@
public void a(PacketPlayInResourcePackStatus packetplayinresourcepackstatus) {}
public void a(IChatBaseComponent ichatbasecomponent) {
@ -504,7 +526,7 @@
if (this.minecraftServer.S() && this.player.getName().equals(this.minecraftServer.R())) {
PlayerConnection.c.info("Stopping singleplayer server as player logged out");
this.minecraftServer.safeShutdown();
@@ -511,6 +791,15 @@
@@ -511,6 +813,15 @@
return;
}
}
@ -520,7 +542,7 @@
try {
this.networkManager.handle(packet);
@@ -524,18 +813,34 @@
@@ -524,18 +835,34 @@
}
public void a(PacketPlayInHeldItemSlot packetplayinhelditemslot) {
@ -557,7 +579,7 @@
ChatMessage chatmessage = new ChatMessage("chat.cannotSend", new Object[0]);
chatmessage.getChatModifier().setColor(EnumChatFormat.RED);
@@ -548,39 +853,247 @@
@@ -548,39 +875,247 @@
for (int i = 0; i < s.length(); ++i) {
if (!SharedConstants.isAllowedChatCharacter(s.charAt(i))) {
@ -673,7 +695,7 @@
+ @Override
+ protected Object evaluate() {
+ org.bukkit.Bukkit.getPluginManager().callEvent(queueEvent);
+
+ if (queueEvent.isCancelled()) {
+ return null;
+ }
@ -707,7 +729,7 @@
+ if (event.isCancelled()) {
+ return;
+ }
+
+ s = String.format(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage());
+ minecraftServer.console.sendMessage(s);
+ if (((LazyPlayerSet) event.getRecipients()).isLazy()) {
@ -769,7 +791,7 @@
+ float f6 = MathHelper.sin(-f1 * 0.017453292F);
+ float f7 = f4 * f5;
+ float f8 = f3 * f5;
+ double d3 = 5.0D;
+ double d3 = player.playerInteractManager.getGameMode() == EnumGamemode.CREATIVE ? 5.0D : 4.5D;
+ Vec3D vec3d1 = vec3d.add((double) f7 * d3, (double) f6 * d3, (double) f8 * d3);
+ MovingObjectPosition movingobjectposition = this.player.world.rayTrace(vec3d, vec3d1, false);
+
@ -813,7 +835,7 @@
this.player.z();
switch (SwitchHelperCommandActionType.b[packetplayinentityaction.b().ordinal()]) {
case 1:
@@ -601,7 +1114,7 @@
@@ -601,7 +1136,7 @@
case 5:
this.player.a(false, true, true);
@ -822,7 +844,7 @@
break;
case 6:
@@ -623,6 +1136,7 @@
@@ -623,6 +1158,7 @@
}
public void a(PacketPlayInUseEntity packetplayinuseentity) {
@ -830,7 +852,7 @@
PlayerConnectionUtils.ensureMainThread(packetplayinuseentity, this, this.player.u());
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
Entity entity = packetplayinuseentity.a((World) worldserver);
@@ -637,18 +1151,72 @@
@@ -637,18 +1173,72 @@
}
if (this.player.h(entity) < d0) {
@ -904,7 +926,7 @@
}
}
}
@@ -663,7 +1231,8 @@
@@ -663,7 +1253,8 @@
switch (SwitchHelperCommandActionType.c[enumclientcommand.ordinal()]) {
case 1:
if (this.player.viewingCredits) {
@ -914,7 +936,7 @@
} else if (this.player.u().getWorldData().isHardcore()) {
if (this.minecraftServer.S() && this.player.getName().equals(this.minecraftServer.R())) {
this.player.playerConnection.disconnect("You have died. Game over, man, it\'s game over!");
@@ -694,11 +1263,17 @@
@@ -694,11 +1285,17 @@
}
public void a(PacketPlayInCloseWindow packetplayinclosewindow) {
@ -932,7 +954,7 @@
PlayerConnectionUtils.ensureMainThread(packetplayinwindowclick, this, this.player.u());
this.player.z();
if (this.player.activeContainer.windowId == packetplayinwindowclick.a() && this.player.activeContainer.c(this.player)) {
@@ -711,7 +1286,269 @@
@@ -711,7 +1308,269 @@
this.player.a(this.player.activeContainer, (List) arraylist);
} else {
@ -1203,7 +1225,7 @@
if (ItemStack.matches(packetplayinwindowclick.e(), itemstack)) {
this.player.playerConnection.sendPacket(new PacketPlayOutTransaction(packetplayinwindowclick.a(), packetplayinwindowclick.d(), true));
@@ -772,8 +1609,50 @@
@@ -772,8 +1631,50 @@
}
boolean flag1 = packetplayinsetcreativeslot.a() >= 1 && packetplayinsetcreativeslot.a() < 36 + PlayerInventory.getHotbarSize();
@ -1255,7 +1277,7 @@
if (flag1 && flag2 && flag3) {
if (itemstack == null) {
@@ -796,6 +1675,7 @@
@@ -796,6 +1697,7 @@
}
public void a(PacketPlayInTransaction packetplayintransaction) {
@ -1263,7 +1285,7 @@
PlayerConnectionUtils.ensureMainThread(packetplayintransaction, this, this.player.u());
Short oshort = (Short) this.n.get(this.player.activeContainer.windowId);
@@ -806,6 +1686,7 @@
@@ -806,6 +1708,7 @@
}
public void a(PacketPlayInUpdateSign packetplayinupdatesign) {
@ -1271,7 +1293,7 @@
PlayerConnectionUtils.ensureMainThread(packetplayinupdatesign, this, this.player.u());
this.player.z();
WorldServer worldserver = this.minecraftServer.getWorldServer(this.player.dimension);
@@ -822,10 +1703,24 @@
@@ -822,10 +1725,24 @@
if (!tileentitysign.b() || tileentitysign.c() != this.player) {
this.minecraftServer.warning("Player " + this.player.getName() + " just tried to change non-editable sign");
@ -1297,7 +1319,7 @@
tileentitysign.update();
worldserver.notify(blockposition);
}
@@ -847,11 +1742,28 @@
@@ -847,11 +1764,28 @@
public void a(PacketPlayInAbilities packetplayinabilities) {
PlayerConnectionUtils.ensureMainThread(packetplayinabilities, this, this.player.u());
@ -1327,7 +1349,7 @@
ArrayList arraylist = Lists.newArrayList();
Iterator iterator = this.minecraftServer.tabCompleteCommand(this.player, packetplayintabcomplete.a(), packetplayintabcomplete.b()).iterator();
@@ -891,13 +1803,15 @@
@@ -891,13 +1825,15 @@
itemstack1 = this.player.inventory.getItemInHand();
if (itemstack1 != null) {
if (itemstack.getItem() == Items.WRITABLE_BOOK && itemstack.getItem() == itemstack1.getItem()) {
@ -1344,7 +1366,7 @@
return;
} finally {
packetdataserializer.release();
@@ -909,27 +1823,31 @@
@@ -909,27 +1845,31 @@
try {
itemstack = packetdataserializer.i();
@ -1388,7 +1410,7 @@
return;
} finally {
packetdataserializer.release();
@@ -946,6 +1864,7 @@
@@ -946,6 +1886,7 @@
}
} catch (Exception exception2) {
PlayerConnection.c.error("Couldn\'t select trade", exception2);
@ -1396,7 +1418,7 @@
}
} else if ("MC|AdvCdm".equals(packetplayincustompayload.a())) {
if (!this.minecraftServer.getEnableCommandBlock()) {
@@ -986,6 +1905,7 @@
@@ -986,6 +1927,7 @@
}
} catch (Exception exception3) {
PlayerConnection.c.error("Couldn\'t set command block", exception3);
@ -1404,7 +1426,7 @@
} finally {
packetdataserializer.release();
}
@@ -1011,6 +1931,7 @@
@@ -1011,6 +1953,7 @@
}
} catch (Exception exception4) {
PlayerConnection.c.error("Couldn\'t set beacon", exception4);
@ -1412,7 +1434,7 @@
}
}
} else if ("MC|ItemName".equals(packetplayincustompayload.a()) && this.player.activeContainer instanceof ContainerAnvil) {
@@ -1026,6 +1947,27 @@
@@ -1026,6 +1969,27 @@
containeranvil.a("");
}
}