258 Commits

Author SHA1 Message Date
Owen1212055
c1279f7751
#1209: Clean up various patches 2023-06-24 17:15:05 +10:00
Jishuna
44a4b5649d
SPIGOT-7380: Add PlayerInteractEvent#getClickedPosition and ChiseledBookshelf#getSlot 2023-06-17 14:31:40 +10:00
md_5
63b46678a5
Fix another mistake in previous commits causing server crash 2023-06-12 21:02:46 +10:00
Doc
40945171bf
#1182: Consolidate Preconditions use and minor cleanup 2023-06-12 19:41:02 +10:00
Doc
9a784ee889
SPIGOT-7383: Add EntityDamageEvent.DamageCause#KILL and EntityDamageEvent.DamageCause#WORLD_BORDER 2023-06-12 08:17:09 +10:00
md_5
245f2be151
Implement SpawnerSpawnEvent
Co-authored-by: Andy Shulman <andy.shulman@hotmail.com>
2023-06-10 07:22:51 +10:00
md_5
e1188ed3a2
Update to Minecraft 1.20 2023-06-08 01:30:00 +10:00
Jishuna
563d422268
SPIGOT-519: Add TNTPrimeEvent
Thanks to Pokechu22 for an earlier implementation
2023-05-03 20:46:43 +10:00
FreeSoccerHDX
bfd8b1ac82
SPIGOT-7209: Accessors and events for player's exp cooldown 2023-04-21 18:46:56 +10:00
Parker Hawke
187bdd463f
#1160: Add more bell API 2023-04-02 14:35:13 +10:00
Doc
58504fa61b
SPIGOT-7302: Fix more issues with EntityDamageByEntity
- Fix Projectile damage by dispenser
- Fix cases where only exists a direct entity damager
2023-03-19 18:48:43 +11:00
Doc
f7707086d1
SPIGOT-7299: Fix indirect/anvil damage events and minor improvements 2023-03-17 07:32:54 +11:00
md_5
cef8bd9933
SPIGOT-7294: Call EntityDamageEvent for Interaction entity 2023-03-16 07:15:33 +11:00
md_5
e1fc95c506
Fix crash with 1.20 smithing table 2023-03-15 18:43:20 +11:00
md_5
bcedf28a1b
Update to Minecraft 1.19.4 2023-03-15 03:30:00 +11:00
FreeSoccerHDX
ab1586c2fb
#1123: Add PrepareGrindstoneEvent 2022-12-13 19:28:47 +11:00
md_5
19e6be0209
Update to Minecraft 1.19.3 2022-12-08 03:00:00 +11:00
Parker Hawke
5329dd6fd2
#1107: Add getHand() to all relevant events 2022-10-02 09:07:14 +11:00
DerFrZocker
622dbe6c24
SPIGOT-7068: SKULK and SKULK_VEIN BlockSpreadEvents Still do not reference the correct source (SKULK_CATALYST) 2022-06-19 21:48:24 +10:00
Doc
9dcd46530f
#1067: Add preview chat option in ServerListPingEvent 2022-06-18 20:55:26 +10:00
Doc
4b60bfd18d
#1059: Add DamageCause.SONIC_BOOM 2022-06-09 21:04:03 +10:00
DerFrZocker
7bc728a6b8
#1045: Revert changes to persistence required checks 2022-05-03 23:13:03 +10:00
md_5
a672a53151
Clean up callBlockDamageEvent 2022-02-02 08:56:24 +11:00
FreeSoccerHDX
8e1bdeef50
SPIGOT-6910: Add BlockDamageAbortEvent 2022-02-02 08:56:23 +11:00
DerFrZocker
3a8161fe41
SPIGOT-6639: During an EntityDamageEvent with damage from blocks, damaging any entity throws an error 2022-01-23 09:06:06 +11:00
DerFrZocker
cc86ab1886
SPIGOT-5339, SPIGOT-6252, SPIGOT-6777: Only cancel knockback if the damage event was canceled 2022-01-03 18:07:01 +01:00
Rafael S. M. Santos
fd3478bc77
#967: Store last lava contact location for events 2021-12-04 08:06:32 +11:00
md_5
a7b8b0270a
Update to Minecraft 1.18-pre5 2021-11-22 09:00:00 +11:00
blablubbabc
dc764e7a2f
#877: Improve and simplify CraftBlockState 2021-09-29 18:56:16 +10:00
DerFrZocker
15f27fc710
SPIGOT-6547: Chunk#getEntities() doesn't return all entities immediately after chunk load 2021-09-01 19:01:52 +10:00
Doc
c30e8f8d51
#913: Handle campfire damage with EntityDamageByBlockEvent 2021-08-11 19:05:08 +10:00
DerFrZocker
97a4f34a8d
SPIGOT-2222, SPIGOT-6687: Pre-set keepLevel and only use it 2021-08-11 18:49:49 +10:00
Mitchell Sulkowski
3ad0fb1c04
#901: Fix PlayerStatisticIncrementEvent spam 2021-07-26 19:32:51 +10:00
md_5
9e06bb2a26
SPIGOT-6663: Chicken Jockeys chickens don't despawn 2021-07-22 09:53:26 +10:00
Doc
2f038f2de0
#886: Add new Causes for LightningStrikeEvent 2021-07-13 19:16:36 +10:00
md_5
cbe0ac7ce1
SPIGOT-6616: Cancellable StriderTemperatureChangeEvent 2021-07-03 09:36:51 +10:00
md_5
6ed400043b
SPIGOT-6560: Crash when falling stalactite hits player 2021-06-15 08:01:07 +10:00
md_5
da425fa23d
SPIGOT-6518: Anvils falling onto dripstone can sometimes crash server 2021-06-12 08:54:51 +10:00
md_5
89e2b1270f
SPIGOT-6517: Spider jockey crash on dripstone 2021-06-12 08:09:44 +10:00
md_5
cbf2f67802
SPIGOT-6508: Rename conflicted getServer 2021-06-11 21:40:36 +10:00
md_5
e2f5ea34e9
Update to Minecraft 1.17 2021-06-11 15:00:00 +10:00
Lars Dormans
fd905ab527
#703: Add piglin bartering API 2021-05-28 09:02:42 +10:00
Martoph
7c4adc61d0
#776: Add ability to cancel ProjectileHitEvent 2021-05-09 16:51:44 +10:00
Julian van den Berkmortel
b6fdc7adb2
SPIGOT-6200: Improve entity events when summon command is used
* Calls the LightningStrikeEvent for summoned lightning
* Uses the new COMMAND SpawnReason for other entities
2021-05-09 16:33:34 +10:00
DiamondDagger590
c5494d195a
#683: Add PlayerBucketFishEvent 2021-04-25 08:34:44 +10:00
md_5
721c4966be
SPIGOT-6411: The PlayerEditBookEvent is not called when the player edits a book in the off-hand. 2021-04-07 15:03:29 +10:00
md_5
90d6905b15
Repackage NMS 2021-03-16 09:00:00 +11:00
Martoph
509e523c57
#792: Add EntityExhaustionEvent 2021-03-04 08:28:05 +11:00
md_5
aeb95e3a30
Add more checkstyle checks 2021-01-31 10:08:41 +11:00
blablubbabc
560b65c4f8
#707, SPIGOT-5063, SPIGOT-5304, SPIGOT-5656, SPIGOT-3206, SPIGOT-5350, SPIGOT-5980, SPIGOT-4672: Persist the exact internal text representation where possible.
Issues resolved by this:
* SPIGOT-5063: Internal text representation of ItemStacks changes during ItemStack serialization. This issue was initially primarily concerned with the conversion between color text attributes to legacy color codes.
* SPIGOT-5304: Internal text representation of ItemStacks changes when opening the inventory (in creative mode). In particularly, this issue is also concerned with the conversion between plain text representations to non-plain ones.
* SPIGOT-5656: Internal text representation of ItemStacks changes during ItemStack serialization. This issue is particularly concerned with reordering of text attributes in the text's Json representation.
* SPIGOT-3206: Internal text representation of book pages changes during ItemStack serialization.
* SPIGOT-5350: Any non-plain text features are stripped from books during ItemStack serialization.
* SPIGOT-5980: Written books are marked as 'resolved' during ItemStack serialization and on various inventory interactions, even though they aren't, and thereby breaking any non-resolved page contents.
* SPIGOT-4672: Since item display names are serialized in their internal Json representation, any translatable components get properly persisted as well now.

---------

Minecraft uses text components to represent text. Internally Minecraft stores these components as Json formatted Strings and dynamically parses the text components from this Json representation whenever required.

In some cases Minecraft will create the text components and then convert them to Json itself for the internal storage. In other cases the Json representation is specified by users (eg. in Minecraft give commands, loot tables, mob equipment specified via Minecraft's summon commands, etc.).
There are many different ways in which the same text components can be represented in Json. When Minecraft compares objects which store this textual information, it takes the exact Json representation into account to determine whether the objects are considered equal. For example, ItemStacks will not match (and therefore not stack) if there is a difference in this internal Json representation for at least one if the item's text attributes (such as display name, lore, book pages, etc.). And when specifying nbt data in command selectors (eg. to only match entities/players which hold an item with specific name), the selector compares the raw Json representation as well.

As long as the Json representation is valid and can be parsed, Minecraft will not modify or normalize it.
However, under various circumstances Spigot converts this text information from the internal Json representation to text components (and in some cases even to plain text with legacy color codes) and then later tries to convert the text from these representations back to text components in the Json representation. Because this backwards conversion is in many cases not able to reproduce the original Json representation, the internal data of some affected Minecraft objects (ItemStacks, TileEntities, Entities, etc.) will in some cases get modified.

One especially notable situation in which this issue can come up is Bukkit's configuration serialization of ItemStacks: When a plugin serializes and later deserializes ItemStacks with display name, localized name, lore, or book pages of signed books, Spigot would convert these textual ItemStack attributes to plain text with legacy color codes and later try to convert those back to chat components in the Json representation. If the reconstructed Json representation does not match the original representation, the deserialized ItemStacks would no longer match nor stack with any original ItemStacks.

This case is particularly common if the original ItemStacks are created by users via some vanilla Minecraft mechanism (eg. Minecraft's give command, loot tables, mob equipment specified via Minecraft's summon command, etc.) and the used internal text representation for the created ItemStacks does not match the text representation produced by Spigot. This is also quite likely to be case, because the internal text representation produced by Spigot can sometimes be slightly verbose and, until recently, contained legacy color codes which cannot be used in Minecraft commands in-game.
However, this issue is not limited to items created by users, but affects items created by Minecraft itself as well.

Other cases in which Spigot itself (without any plugins involved) will convert between these text representations include dragging items around inside the inventory or opening the inventory while in creative mode. In these cases Spigot creates Bukkit representations of the affected items for use in Bukkit events and then, after the events have been handled, converts these Bukkit representations back to Minecraft items. See for example SPIGOT-5656 and SPIGOT-5304.

The idea of these changes is to avoid this back and forth conversion between the internal Json representation and the text component or plain text representations in various situations in which it is not actually required:
* CraftMetaItem stores the raw original Json representation for the display name, localized name, lore and pages of signed books now. As long as no plugin modifies these text attributes via the API, they can be reapplied in their original form to an ItemStack.
* The configuration serialization will serialize the original Json representation for these text attributes now so that it can also be restored during deserialization.
* However, in order to still be able to deserialize previously serialized items, and in order to allow users to specify text in the more simple plain representation in configuration files, we also still accept plain text during deserialization. Our approach is to check if the serialized text contains legacy color codes, in which case we convert it to chat components using our own converter and then to Json. Otherwise we try to parse it via Minecraft's Json parser. If the parsing fails due to the text not being valid Json, we interpret the text as plain text and convert it via our own converter as well.
* Various duplicated code has been removed from CraftMetaBookSigned and instead the base CraftMetaBook class allows sub classes to override the relevant aspects of how pages are parsed, serialized and deserialized.
* The BlockStates for command blocks and signs preemptively retrieved the custom name and sign line components, converted them to plain text and later converted them back to text components when applying the BlockState. We now only perform this conversion if a plugin has explicitly modified these texts.

Other changes:
* Minor: We also retrieve, convert and update a few other BlockState attributes directly from the underlying snapshot and only when requested by plugins now.
* SPIGOT-5980: Written books did not properly persist their 'resolved' attribute, resulting in unresolved book pages not getting resolved.
* There are methods to get and set the resolved value for books. However, these are not yet exposed in Bukkit.
* Minor fix: CraftMetaBook#isBookEmpty did not check some of the book attributes. This is probably a minor issue, but for consistency reasons there are checks for the missing attribute(s) now.

----
Covered cases
---
* By remembering the raw original String data, we can persist the exact text representation (eg. the ordering of elements within the Json text object (SPIGOT-5656), used style of escaping quotes (single quotes, escaped double quotes, etc.), use of plain texts (SPIGOT-5304), used boolean style, modern text component features such as translatable texts (SPIGOT-4672), etc.). All of these differences would otherwise cause the ItemStack to no longer be considered equal to its original.
* An empty String in the serialized config data results in no display name rather than an empty display name, like before. An item with explicitly empty display name (`{display: {Name: '""'}}`) is saved as `'""'` and can also be loaded from that representation again.
* Any plain texts, with or without color codes, which don't parse as Json (eg. `display-name: 'Bla'`) are still getting run through Spigot's text to components converter, like before.
* We can now also persist empty but explicitly present lore (`{display:{Lore:[]}}`). Previously this would get removed when the ItemMeta gets reapplied to the item. And ItemMeta#equals would return true for items with and without this empty lore data, even though Minecraft considers them to be different. For plugins using the API there should be no change: #hasLore still checks whether the lore is both present and not empty, and #getLore returns an empty list instead of null in this case (however, it previously already returned an empty list in this case). And setting the lore to an empty list via #setLore will still result in an item with no lore.
* Similarly, we can also persist explicitly specified but empty lists of book pages now.

----
Cases that are not covered (i.e. which may lead to changes in items), but were already not covered previously:
----
* NBT data for text that is not actually of type String.
* Empty or unexpected entries within the display compound.
* Variations in the NBT data representation in item features other than the above mentioned ones.
* Texts containing color codes. During deserialization these texts get interpreted as plain text and converted to a text component representation. This will break the serialization of any ItemStacks which actually use a text component representation with embedded color codes for some reason. Usually the likelihood for encountering such items in practice would probably be small. However, in the past (pre MC 1.16) Spigot would actually produce such items during ItemStack deserialization or when plugins created ItemStack via the Bukkit API. However, Spigot has changed the text representation it produces in MC 1.16, so any previously created and still existing items with this text representation are already problematic anyways now. See SPIGOT-5964. A fix for this linked issue (eg. the automatic conversion of these items) would probably resolve this deficit here as well.
* Spigot's String to text components converter produces quite verbose components since 1.16. See SPIGOT-5964 as well. However, this applies regardless of the changes of this PR.
* Book ItemStacks with more pages than 100 pages or oversized pages are truncated (like before) and may therefore change.
hange.
2021-01-01 08:53:14 +11:00