Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Commit

Permalink
Remove Bukkit PlayerInteract doubling (needs testing)
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Feb 5, 2016
1 parent dfe4ede commit 34e591d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 89 deletions.
113 changes: 51 additions & 62 deletions patches/net/minecraft/network/NetHandlerPlayServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
ItemStack itemstack = this.playerEntity.inventory.getCurrentItem();
boolean flag = false;
boolean placeResult = true;
@@ -533,11 +815,21 @@
@@ -533,11 +815,23 @@
return;
}

Expand All @@ -480,7 +480,9 @@
+ worldserver); // Cauldron - rename event
+ // CraftBukkit start
+ int itemstackAmount = itemstack.stackSize;
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.playerEntity, Action.RIGHT_CLICK_AIR, itemstack);
+ //CraftEventFactory.callPlayerInteractEvent(this.playerEntity, Action.RIGHT_CLICK_AIR, itemstack);
+ org.bukkit.event.player.PlayerInteractEvent event = forgeEvent.cb;
+
+
+ if (forgeEvent.useItem != cpw.mods.fml.common.eventhandler.Event.Result.DENY && event.useItemInHand() != Event.Result.DENY)
{
Expand All @@ -494,7 +496,7 @@
}
else if (p_147346_1_.func_149571_d() >= this.serverController.getBuildLimit() - 1 && (p_147346_1_.func_149568_f() == 1 || p_147346_1_.func_149571_d() >= this.serverController.getBuildLimit()))
{
@@ -548,17 +840,24 @@
@@ -548,17 +842,24 @@
}
else
{
Expand Down Expand Up @@ -527,7 +529,7 @@
flag = true;
}

@@ -615,7 +914,7 @@
@@ -615,7 +916,7 @@
this.playerEntity.openContainer.detectAndSendChanges();
this.playerEntity.isChangingQuantityOnly = false;

Expand All @@ -536,7 +538,7 @@
{
this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem()));
}
@@ -624,13 +923,33 @@
@@ -624,13 +925,33 @@

public void onDisconnect(IChatComponent p_147231_1_)
{
Expand Down Expand Up @@ -575,7 +577,7 @@

if (this.serverController.isSinglePlayer() && this.playerEntity.getCommandSenderName().equals(this.serverController.getServerOwner()))
{
@@ -657,6 +976,18 @@
@@ -657,6 +978,18 @@
}
}

Expand All @@ -594,7 +596,7 @@
try
{
this.netManager.scheduleOutboundPacket(p_147359_1_, new GenericFutureListener[0]);
@@ -679,20 +1010,37 @@
@@ -679,20 +1012,37 @@

public void processHeldItemChange(C09PacketHeldItemChange p_147355_1_)
{
Expand Down Expand Up @@ -633,7 +635,7 @@
{
ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]);
chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
@@ -708,51 +1056,385 @@
@@ -708,51 +1058,385 @@
{
if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
{
Expand Down Expand Up @@ -690,7 +692,11 @@
}
- else
+ else if (s.isEmpty())
+ {
{
- ChatComponentTranslation chatcomponenttranslation1 = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.func_145748_c_(), ForgeHooks.newChatWithLinks(s)}); // Fixes chat links
- chatcomponenttranslation1 = ForgeHooks.onServerChatEvent(this, s, chatcomponenttranslation1);
- if (chatcomponenttranslation1 == null) return;
- this.serverController.getConfigurationManager().sendChatMsgImpl(chatcomponenttranslation1, false);
+ logger.warn(this.playerEntity.getCommandSenderName() + " tried to send an empty message");
+ }
+ else if (getPlayerB().isConversing())
Expand All @@ -704,20 +710,19 @@
+ this.sendPacket(new S02PacketChat(chatcomponenttranslation));
+ }
+ else if (true)
{
- ChatComponentTranslation chatcomponenttranslation1 = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.func_145748_c_(), ForgeHooks.newChatWithLinks(s)}); // Fixes chat links
- chatcomponenttranslation1 = ForgeHooks.onServerChatEvent(this, s, chatcomponenttranslation1);
- if (chatcomponenttranslation1 == null) return;
- this.serverController.getConfigurationManager().sendChatMsgImpl(chatcomponenttranslation1, false);
+ {
+ this.chat(s, true);
+ // CraftBukkit end - the below is for reference. :)
}

- this.chatSpamThresholdCount += 20;
-
- if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().func_152596_g(this.playerEntity.getGameProfile()))
+ // CraftBukkit start - replaced with thread safe throttle
+ // this.chatSpamThresholdCount += 20;
+ if (chatSpamField.addAndGet(this, 20) > 200 && !this.serverController.getConfigurationManager().func_152596_g(this.playerEntity.getGameProfile()))
+ {
{
- this.kickPlayerFromServer("disconnect.spam");
+ if (p_147354_1_.hasPriority())
+ {
+ Waitable waitable = new Waitable() {
Expand Down Expand Up @@ -747,13 +752,12 @@
+ {
+ this.kickPlayerFromServer("disconnect.spam");
+ }

- if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().func_152596_g(this.playerEntity.getGameProfile()))
+ // CraftBukkit end
+ }
+ }
+ }
+
+ // CraftBukkit end
}
}
}

+ // CraftBukkit start
+ public void chat(String s, boolean async)
+ {
Expand All @@ -779,8 +783,7 @@
+
+ if (chatcomponenttranslation1 != null
+ && chatcomponenttranslation1.getFormatArgs()[chatcomponenttranslation1.getFormatArgs().length - 1] instanceof String)
{
- this.kickPlayerFromServer("disconnect.spam");
+ {
+ // use event message from Forge
+ s = (String) chatcomponenttranslation1.getFormatArgs()[chatcomponenttranslation1.getFormatArgs().length - 1];
+ }
Expand Down Expand Up @@ -874,11 +877,11 @@
+ recipient.sendMessage(s);
+ }
+ }
}
}
}
+ }
+ }
+ }
+ // CraftBukkit end
+
private void handleSlashCommand(String p_147361_1_)
{
- this.serverController.getCommandManager().executeCommand(this.playerEntity, p_147361_1_);
Expand Down Expand Up @@ -1031,7 +1034,7 @@
if (p_147357_1_.func_149513_d() == 1)
{
this.playerEntity.setSneaking(true);
@@ -772,7 +1454,7 @@
@@ -772,7 +1456,7 @@
else if (p_147357_1_.func_149513_d() == 3)
{
this.playerEntity.wakeUpPlayer(false, true, true);
Expand All @@ -1040,7 +1043,7 @@
}
else if (p_147357_1_.func_149513_d() == 6)
{
@@ -789,8 +1471,20 @@
@@ -789,8 +1473,20 @@

public void processUseEntity(C02PacketUseEntity p_147340_1_)
{
Expand All @@ -1062,7 +1065,7 @@
this.playerEntity.func_143004_u();

if (entity != null)
@@ -805,9 +1499,53 @@
@@ -805,9 +1501,53 @@

if (this.playerEntity.getDistanceSqToEntity(entity) < d0)
{
Expand Down Expand Up @@ -1116,7 +1119,7 @@
}
else if (p_147340_1_.func_149565_c() == C02PacketUseEntity.Action.ATTACK)
{
@@ -819,6 +1557,13 @@
@@ -819,6 +1559,13 @@
}

this.playerEntity.attackTargetEntityWithCurrentItem(entity);
Expand All @@ -1130,7 +1133,7 @@
}
}
}
@@ -834,7 +1579,18 @@
@@ -834,7 +1581,18 @@
case 1:
if (this.playerEntity.playerConqueredTheEnd)
{
Expand All @@ -1150,7 +1153,7 @@
}
else if (this.playerEntity.getServerForPlayer().getWorldInfo().isHardcoreModeEnabled())
{
@@ -871,16 +1627,460 @@
@@ -871,16 +1629,460 @@

public void processCloseWindow(C0DPacketCloseWindow p_147356_1_)
{
Expand Down Expand Up @@ -1612,7 +1615,7 @@

if (ItemStack.areItemStacksEqual(p_147351_1_.func_149546_g(), itemstack))
{
@@ -903,6 +2103,12 @@
@@ -903,6 +2105,12 @@
}

this.playerEntity.sendContainerAndContentsToPlayer(this.playerEntity.openContainer, arraylist);
Expand All @@ -1625,7 +1628,7 @@
}
}
}
@@ -925,8 +2131,60 @@
@@ -925,8 +2133,60 @@
boolean flag = p_147344_1_.func_149627_c() < 0;
ItemStack itemstack = p_147344_1_.func_149625_d();
boolean flag1 = p_147344_1_.func_149627_c() >= 1 && p_147344_1_.func_149627_c() < 36 + InventoryPlayer.getHotbarSize();
Expand Down Expand Up @@ -1687,7 +1690,7 @@

if (flag1 && flag2 && flag3)
{
@@ -956,6 +2214,11 @@
@@ -956,6 +2216,11 @@

public void processConfirmTransaction(C0FPacketConfirmTransaction p_147339_1_)
{
Expand All @@ -1699,7 +1702,7 @@
Short oshort = (Short)this.field_147372_n.lookup(this.playerEntity.openContainer.windowId);

if (oshort != null && p_147339_1_.func_149533_d() == oshort.shortValue() && this.playerEntity.openContainer.windowId == p_147339_1_.func_149532_c() && !this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
@@ -966,6 +2229,11 @@
@@ -966,6 +2231,11 @@

public void processUpdateSign(C12PacketUpdateSign p_147343_1_)
{
Expand All @@ -1711,23 +1714,23 @@
this.playerEntity.func_143004_u();
WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);

@@ -980,6 +2248,7 @@
@@ -980,6 +2250,7 @@
if (!tileentitysign.func_145914_a() || tileentitysign.func_145911_b() != this.playerEntity)
{
this.serverController.logWarning("Player " + this.playerEntity.getCommandSenderName() + " just tried to change non-editable sign");
+ this.sendPacket(new S33PacketUpdateSign(p_147343_1_.func_149588_c(), p_147343_1_.func_149586_d(), p_147343_1_.func_149585_e(), tileentitysign.signText)); // CraftBukkit
return;
}
}
@@ -990,6 +2259,7 @@
@@ -990,6 +2261,7 @@
for (j = 0; j < 4; ++j)
{
boolean flag = true;
+ p_147343_1_.func_149589_f()[j] = p_147343_1_.func_149589_f()[j].replaceAll("\uF700", "").replaceAll("\uF701", ""); // Spigot - Mac OSX sends weird chars

if (p_147343_1_.func_149589_f()[j].length() > 15)
{
@@ -1018,7 +2288,29 @@
@@ -1018,7 +2290,29 @@
int k = p_147343_1_.func_149586_d();
i = p_147343_1_.func_149585_e();
TileEntitySign tileentitysign1 = (TileEntitySign)tileentity;
Expand Down Expand Up @@ -1758,7 +1761,7 @@
tileentitysign1.markDirty();
worldserver.markBlockForUpdate(j, k, i);
}
@@ -1041,7 +2333,22 @@
@@ -1041,7 +2335,22 @@

public void processPlayerAbilities(C13PacketPlayerAbilities p_147348_1_)
{
Expand All @@ -1782,15 +1785,7 @@
}

public void processTabComplete(C14PacketTabComplete p_147341_1_)
@@ -1068,7 +2375,6 @@
PacketBuffer packetbuffer;
ItemStack itemstack;
ItemStack itemstack1;
-
if ("MC|BEdit".equals(p_147349_1_.func_149559_c()))
{
packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));
@@ -1093,16 +2399,18 @@
@@ -1093,16 +2401,18 @@
{
if (itemstack.getItem() == Items.writable_book && itemstack.getItem() == itemstack1.getItem())
{
Expand All @@ -1813,7 +1808,7 @@
}
finally
{
@@ -1135,19 +2443,18 @@
@@ -1135,19 +2445,18 @@

if (itemstack.getItem() == Items.written_book && itemstack1.getItem() == Items.writable_book)
{
Expand All @@ -1839,7 +1834,7 @@
}
finally
{
@@ -1174,9 +2481,12 @@
@@ -1174,9 +2483,12 @@
((ContainerMerchant)container).setCurrentRecipeIndex(i);
}
}
Expand All @@ -1853,7 +1848,7 @@
}
}
else if ("MC|AdvCdm".equals(p_147349_1_.func_149559_c()))
@@ -1222,9 +2532,12 @@
@@ -1222,9 +2534,12 @@
this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.setCommand.success", new Object[] {s1}));
}
}
Expand All @@ -1868,7 +1863,7 @@
}
finally
{
@@ -1257,9 +2570,12 @@
@@ -1257,9 +2572,12 @@
tileentitybeacon.markDirty();
}
}
Expand All @@ -1883,7 +1878,7 @@
}
}
}
@@ -1281,6 +2597,13 @@
@@ -1281,6 +2599,13 @@
containerrepair.updateItemName("");
}
}
Expand All @@ -1897,7 +1892,7 @@
}
}

@@ -1292,6 +2615,21 @@
@@ -1292,6 +2617,21 @@
}
}

Expand All @@ -1919,9 +1914,3 @@
static final class SwitchEnumState
{
static final int[] field_151290_a = new int[C16PacketClientStatus.EnumState.values().length];
@@ -1327,4 +2665,4 @@
}
}
}
-}
+}
Loading

0 comments on commit 34e591d

Please sign in to comment.