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

Commit

Permalink
Change Interaction Expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
sameer committed Feb 9, 2016
1 parent c2c67d8 commit 68760c3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 73 deletions.
61 changes: 30 additions & 31 deletions patches/net/minecraft/network/NetHandlerPlayServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,12 @@
ItemStack itemstack = this.playerEntity.inventory.getCurrentItem();
boolean flag = false;
boolean placeResult = true;
@@ -532,12 +814,21 @@
@@ -532,12 +814,20 @@
{
return;
}
+ org.bukkit.event.player.PlayerInteractEvent event = CraftEventFactory.callPlayerInteractEvent(this.playerEntity, Action.RIGHT_CLICK_AIR, itemstack);
+ PlayerInteractEvent forgeEvent = ForgeEventFactory.onPlayerInteract(playerEntity, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, 0, 0, 0, -1,
+ worldserver, event); // Cauldron - rename event
+ PlayerInteractEvent forgeEvent = ForgeEventFactory.onPlayerInteract(playerEntity, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, 0, 0, 0, -1, worldserver, null); // Cauldron - rename event
+ // CraftBukkit start
+ int itemstackAmount = itemstack.stackSize;

Expand All @@ -495,7 +494,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 +839,24 @@
@@ -548,17 +838,24 @@
}
else
{
Expand Down Expand Up @@ -528,7 +527,7 @@
flag = true;
}

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

Expand All @@ -537,7 +536,7 @@
{
this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem()));
}
@@ -624,14 +922,34 @@
@@ -624,14 +921,34 @@

public void onDisconnect(IChatComponent p_147231_1_)
{
Expand Down Expand Up @@ -577,7 +576,7 @@
if (this.serverController.isSinglePlayer() && this.playerEntity.getCommandSenderName().equals(this.serverController.getServerOwner()))
{
logger.info("Stopping singleplayer server as player logged out");
@@ -657,6 +975,18 @@
@@ -657,6 +974,18 @@
}
}

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

public void processHeldItemChange(C09PacketHeldItemChange p_147355_1_)
{
Expand Down Expand Up @@ -635,7 +634,7 @@
{
ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]);
chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
@@ -708,51 +1055,385 @@
@@ -708,51 +1054,385 @@
{
if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
{
Expand Down Expand Up @@ -1033,7 +1032,7 @@
if (p_147357_1_.func_149513_d() == 1)
{
this.playerEntity.setSneaking(true);
@@ -772,7 +1453,7 @@
@@ -772,7 +1452,7 @@
else if (p_147357_1_.func_149513_d() == 3)
{
this.playerEntity.wakeUpPlayer(false, true, true);
Expand All @@ -1042,7 +1041,7 @@
}
else if (p_147357_1_.func_149513_d() == 6)
{
@@ -789,8 +1470,20 @@
@@ -789,8 +1469,20 @@

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

if (entity != null)
@@ -805,9 +1498,53 @@
@@ -805,9 +1497,53 @@

if (this.playerEntity.getDistanceSqToEntity(entity) < d0)
{
Expand Down Expand Up @@ -1118,7 +1117,7 @@
}
else if (p_147340_1_.func_149565_c() == C02PacketUseEntity.Action.ATTACK)
{
@@ -819,6 +1556,13 @@
@@ -819,6 +1555,13 @@
}

this.playerEntity.attackTargetEntityWithCurrentItem(entity);
Expand All @@ -1132,7 +1131,7 @@
}
}
}
@@ -834,8 +1578,19 @@
@@ -834,8 +1577,19 @@
case 1:
if (this.playerEntity.playerConqueredTheEnd)
{
Expand All @@ -1153,7 +1152,7 @@
else if (this.playerEntity.getServerForPlayer().getWorldInfo().isHardcoreModeEnabled())
{
if (this.serverController.isSinglePlayer() && this.playerEntity.getCommandSenderName().equals(this.serverController.getServerOwner()))
@@ -857,7 +1612,7 @@
@@ -857,7 +1611,7 @@
return;
}

Expand All @@ -1162,7 +1161,7 @@
}

break;
@@ -871,17 +1626,461 @@
@@ -871,17 +1625,461 @@

public void processCloseWindow(C0DPacketCloseWindow p_147356_1_)
{
Expand Down Expand Up @@ -1625,7 +1624,7 @@
if (ItemStack.areItemStacksEqual(p_147351_1_.func_149546_g(), itemstack))
{
this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(p_147351_1_.func_149548_c(), p_147351_1_.func_149547_f(), true));
@@ -903,6 +2102,12 @@
@@ -903,6 +2101,12 @@
}

this.playerEntity.sendContainerAndContentsToPlayer(this.playerEntity.openContainer, arraylist);
Expand All @@ -1638,7 +1637,7 @@
}
}
}
@@ -925,9 +2130,61 @@
@@ -925,9 +2129,61 @@
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 @@ -1701,7 +1700,7 @@
if (flag1 && flag2 && flag3)
{
if (itemstack == null)
@@ -956,6 +2213,11 @@
@@ -956,6 +2212,11 @@

public void processConfirmTransaction(C0FPacketConfirmTransaction p_147339_1_)
{
Expand All @@ -1713,7 +1712,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 +2228,11 @@
@@ -966,6 +2227,11 @@

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

@@ -980,6 +2247,7 @@
@@ -980,6 +2246,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 +2258,7 @@
@@ -990,6 +2257,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 +2287,29 @@
@@ -1018,7 +2286,29 @@
int k = p_147343_1_.func_149586_d();
i = p_147343_1_.func_149585_e();
TileEntitySign tileentitysign1 = (TileEntitySign)tileentity;
Expand Down Expand Up @@ -1772,7 +1771,7 @@
tileentitysign1.markDirty();
worldserver.markBlockForUpdate(j, k, i);
}
@@ -1041,7 +2332,22 @@
@@ -1041,7 +2331,22 @@

public void processPlayerAbilities(C13PacketPlayerAbilities p_147348_1_)
{
Expand All @@ -1796,7 +1795,7 @@
}

public void processTabComplete(C14PacketTabComplete p_147341_1_)
@@ -1093,16 +2399,18 @@
@@ -1093,16 +2398,18 @@
{
if (itemstack.getItem() == Items.writable_book && itemstack.getItem() == itemstack1.getItem())
{
Expand All @@ -1819,7 +1818,7 @@
}
finally
{
@@ -1135,19 +2443,18 @@
@@ -1135,19 +2442,18 @@

if (itemstack.getItem() == Items.written_book && itemstack1.getItem() == Items.writable_book)
{
Expand All @@ -1845,7 +1844,7 @@
}
finally
{
@@ -1174,9 +2481,12 @@
@@ -1174,9 +2480,12 @@
((ContainerMerchant)container).setCurrentRecipeIndex(i);
}
}
Expand All @@ -1859,7 +1858,7 @@
}
}
else if ("MC|AdvCdm".equals(p_147349_1_.func_149559_c()))
@@ -1222,9 +2532,12 @@
@@ -1222,9 +2531,12 @@
this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.setCommand.success", new Object[] {s1}));
}
}
Expand All @@ -1874,7 +1873,7 @@
}
finally
{
@@ -1257,9 +2570,12 @@
@@ -1257,9 +2569,12 @@
tileentitybeacon.markDirty();
}
}
Expand All @@ -1889,7 +1888,7 @@
}
}
}
@@ -1281,6 +2597,13 @@
@@ -1281,6 +2596,13 @@
containerrepair.updateItemName("");
}
}
Expand All @@ -1903,7 +1902,7 @@
}
}

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

Expand Down
77 changes: 35 additions & 42 deletions patches/net/minecraftforge/event/ForgeEventFactory.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
PlayerEvent.HarvestCheck event = new PlayerEvent.HarvestCheck(player, block, success);
MinecraftForge.EVENT_BUS.post(event);
return event.success;
@@ -80,27 +94,171 @@
@@ -80,27 +94,164 @@
@Deprecated // Location version below
public static float getBreakSpeed(EntityPlayer player, Block block, int metadata, float original)
{
Expand Down Expand Up @@ -133,29 +133,17 @@
+ public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, int x, int y, int z, int face, org.bukkit.event.player.PlayerInteractEvent eve)
+ {
+ PlayerInteractEvent event = new PlayerInteractEvent(player, action, x, y, z, face, null);
+ org.bukkit.event.block.Action aktor = null;
+ switch (action)
+
+ if(eve != null)
+ {
+ case RIGHT_CLICK_AIR:
+ aktor = org.bukkit.event.block.Action.RIGHT_CLICK_AIR;
+ break;
+ case RIGHT_CLICK_BLOCK:
+ aktor = org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK;
+ break;
+ case LEFT_CLICK_BLOCK:
+ aktor = org.bukkit.event.block.Action.LEFT_CLICK_BLOCK;
+ default:
+ aktor = org.bukkit.event.block.Action.LEFT_CLICK_AIR;
+ break;
+ event.cb = eve;
+ if(eve.isCancelled())
+ {
+ event.setCanceled(true);
+ return event;
+ }
+ }
+
+ if(eve == null)
+ eve = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(player, aktor, x, y, z, face, player.inventory.getCurrentItem());
+
+ event.cb = eve;
+
+ if(eve.isCancelled()) { event.setCanceled(true); return event; }
+
+ if (isSpawn(player) && nonVanilla(player))
+ {
+ event.setCanceled(true);
Expand All @@ -171,31 +159,36 @@
- PlayerInteractEvent event = new PlayerInteractEvent(player, action, x, y, z, face, world);
- MinecraftForge.EVENT_BUS.post(event);
- return event;
+ return onPlayerInteract( player, action, x, y, z, face, world, null);
+ org.bukkit.event.block.Action aktor = null;
+ switch (action)
+ {
+ case RIGHT_CLICK_AIR:
+ aktor = org.bukkit.event.block.Action.RIGHT_CLICK_AIR;
+ break;
+ case RIGHT_CLICK_BLOCK:
+ aktor = org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK;
+ break;
+ case LEFT_CLICK_BLOCK:
+ aktor = org.bukkit.event.block.Action.LEFT_CLICK_BLOCK;
+ default:
+ aktor = org.bukkit.event.block.Action.LEFT_CLICK_AIR;
+ break;
+ }
+ return onPlayerInteract( player, action, x, y, z, face, world, org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(player, aktor, x, y, z, face, player.inventory.getCurrentItem()));
}
+ public static PlayerInteractEvent onPlayerInteract(EntityPlayer player, Action action, int x, int y, int z, int face, World world, org.bukkit.event.player.PlayerInteractEvent eve)
+ {
+ PlayerInteractEvent event = new PlayerInteractEvent(player, action, x, y, z, face, world);
+ org.bukkit.event.block.Action aktor = null;
+ switch (action)
+
+ if(eve != null)
+ {
+ case RIGHT_CLICK_AIR:
+ aktor = org.bukkit.event.block.Action.RIGHT_CLICK_AIR;
+ break;
+ case RIGHT_CLICK_BLOCK:
+ aktor = org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK;
+ break;
+ case LEFT_CLICK_BLOCK:
+ aktor = org.bukkit.event.block.Action.LEFT_CLICK_BLOCK;
+ default:
+ aktor = org.bukkit.event.block.Action.LEFT_CLICK_AIR;
+ break;
+ event.cb = eve;
+ if(eve.isCancelled())
+ {
+ event.setCanceled(true);
+ return event;
+ }
+ }
+ if(eve == null)
+ eve = org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(player, aktor, x, y, z, face, player.inventory.getCurrentItem());

+ event.cb = eve;
+ if(eve.isCancelled()) { event.setCanceled(true); return event; }
+
+ if (isSpawn(player) && nonVanilla(player))
+ {
Expand All @@ -205,13 +198,13 @@
+ } else
+ MinecraftForge.EVENT_BUS.post(event);
+ return event;
+
+ }
+
public static void onPlayerDestroyItem(EntityPlayer player, ItemStack stack)
{
MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, stack));
@@ -182,30 +340,64 @@
@@ -182,30 +333,64 @@
return MinecraftForge.EVENT_BUS.post(new EntityStruckByLightningEvent(entity, bolt));
}

Expand Down

0 comments on commit 68760c3

Please sign in to comment.