-
Notifications
You must be signed in to change notification settings - Fork 31
Fix #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #216
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,9 +90,9 @@ public void onPacketSend(PacketSendEvent event) { | |
| } | ||
| }; | ||
|
|
||
| if (Bukkit.isPrimaryThread() || this.plugin.isEnabled()) { | ||
| if (Bukkit.isPrimaryThread()) { | ||
| task.run(); | ||
| } else { | ||
| } else if (this.plugin.isEnabled()) { | ||
| this.plugin.getScheduler().runNextTick(w -> task.run()); | ||
| } | ||
| } else if (packetType == PacketType.Play.Server.CLOSE_WINDOW){ | ||
|
|
@@ -110,9 +110,9 @@ public void onPacketSend(PacketSendEvent event) { | |
| } | ||
| }; | ||
|
|
||
| if (Bukkit.isPrimaryThread() || this.plugin.isEnabled()) { | ||
| if (Bukkit.isPrimaryThread()) { | ||
| task.run(); | ||
| } else { | ||
| } else if (this.plugin.isEnabled()) { | ||
| this.plugin.getScheduler().runNextTick(w -> task.run()); | ||
| } | ||
| } else if (packetType == PacketType.Play.Server.WINDOW_ITEMS){ | ||
|
|
@@ -148,9 +148,9 @@ public void onPacketSend(PacketSendEvent event) { | |
| } | ||
| }; | ||
|
|
||
| if (Bukkit.isPrimaryThread() || !this.plugin.isEnabled()) { | ||
| if (Bukkit.isPrimaryThread()) { | ||
| task.run(); | ||
| } else { | ||
| } else if (this.plugin.isEnabled()) { | ||
| this.plugin.getScheduler().runNextTick(w -> task.run()); | ||
| } | ||
|
Comment on lines
+151
to
155
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import fr.maxlego08.menu.itemstack.components.spigot.SpigotVariantComponent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import fr.maxlego08.menu.loader.components.paper.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import fr.maxlego08.menu.loader.components.spigot.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import fr.maxlego08.menu.zcore.logger.Logger; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.jetbrains.annotations.NotNull; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.HashMap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -28,7 +29,14 @@ private boolean isPaperAndMiniMessageEnabled(MenuPlugin plugin){ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void initializeDefaultComponents(MenuPlugin plugin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NmsVersion currentVersion = NmsVersion.getCurrentVersion(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.isAttributItemStack()){ // 1.20.5+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.initializeVariantComponents(plugin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.initializeVariantComponents(plugin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Configuration.enableDebug) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Logger.info("Failed to initialize variant item components:"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| e.printStackTrace(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+34
to
+38
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(new SpigotBlockStateItemComponentLoader()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(new SpigotAttributeModifiersItemComponentLoader(plugin)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -131,32 +139,49 @@ public void initializeDefaultComponents(MenuPlugin plugin) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void initializeVariantComponents(MenuPlugin plugin) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NmsVersion currentVersion = NmsVersion.getCurrentVersion(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VariantItemComponentLoaderFactory loaderFactory = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| plugin.isPaper() ? new PaperVariantItemComponentLoader(new PaperVariantComponent()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : new SpigotVariantItemComponentLoader(new SpigotVariantComponent()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderAxolotl()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderCatCollar()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderCatVariant()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderChicken()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderCow()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderFox()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderFrog()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderHorse()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderLlama()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderMushroomCow()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderPainting()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderParrot()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderPig()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderRabbit()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderSalmon()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderSheep()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderShulkerBox()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderTropicalFishBaseColor()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderTropicalFishPatternColor()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderVillager()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderWolfCollar()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderWolfVariant()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.isNewMaterial()){ // 1.13+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderFox()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderMushroomCow()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.isNewNMSVersion()){ // 1.17+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderAxolotl()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.isAttributItemStack()){ // 1.20.5+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderWolfCollar()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderWolfVariant()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderPainting()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.is1_21_5OrNewer()){ // 1.21.5+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderChicken()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderCow()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderPig()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.isNewNBTVersion()) { // 1.18+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderFrog()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.is1_11OrNewer()){ // 1.11+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderLlama()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderShulkerBox()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.is1_12OrNewer()) { // 1.12+ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.registerComponent(loaderFactory.getLoaderParrot()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+156
to
+183
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentVersion.isNewMaterial()){ // 1.13+ | |
| this.registerComponent(loaderFactory.getLoaderFox()); | |
| this.registerComponent(loaderFactory.getLoaderMushroomCow()); | |
| } | |
| if (currentVersion.isNewNMSVersion()){ // 1.17+ | |
| this.registerComponent(loaderFactory.getLoaderAxolotl()); | |
| } | |
| if (currentVersion.isAttributItemStack()){ // 1.20.5+ | |
| this.registerComponent(loaderFactory.getLoaderWolfCollar()); | |
| this.registerComponent(loaderFactory.getLoaderWolfVariant()); | |
| this.registerComponent(loaderFactory.getLoaderPainting()); | |
| } | |
| if (currentVersion.is1_21_5OrNewer()){ // 1.21.5+ | |
| this.registerComponent(loaderFactory.getLoaderChicken()); | |
| this.registerComponent(loaderFactory.getLoaderCow()); | |
| this.registerComponent(loaderFactory.getLoaderPig()); | |
| } | |
| if (currentVersion.isNewNBTVersion()) { // 1.18+ | |
| this.registerComponent(loaderFactory.getLoaderFrog()); | |
| } | |
| if (currentVersion.is1_11OrNewer()){ // 1.11+ | |
| this.registerComponent(loaderFactory.getLoaderLlama()); | |
| this.registerComponent(loaderFactory.getLoaderShulkerBox()); | |
| } | |
| if (currentVersion.is1_12OrNewer()) { // 1.12+ | |
| this.registerComponent(loaderFactory.getLoaderParrot()); | |
| } | |
| this.registerComponent(loaderFactory.getLoaderFox()); | |
| this.registerComponent(loaderFactory.getLoaderMushroomCow()); | |
| this.registerComponent(loaderFactory.getLoaderAxolotl()); | |
| this.registerComponent(loaderFactory.getLoaderWolfCollar()); | |
| this.registerComponent(loaderFactory.getLoaderWolfVariant()); | |
| this.registerComponent(loaderFactory.getLoaderPainting()); | |
| this.registerComponent(loaderFactory.getLoaderFrog()); | |
| this.registerComponent(loaderFactory.getLoaderLlama()); | |
| this.registerComponent(loaderFactory.getLoaderShulkerBox()); | |
| this.registerComponent(loaderFactory.getLoaderParrot()); | |
| if (currentVersion.is1_21_5OrNewer()){ // 1.21.5+ | |
| this.registerComponent(loaderFactory.getLoaderChicken()); | |
| this.registerComponent(loaderFactory.getLoaderCow()); | |
| this.registerComponent(loaderFactory.getLoaderPig()); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
onPacketSendis invoked off the primary thread, this branch schedulestaskbut the method still reads/writesplayerAnimationData(a plainHashMap) on the packet thread whiletaskmutates it on the Bukkit thread. This is a data race. Use aConcurrentHashMap(and ensurePlayerAnimationDataupdates are thread-safe) or move all access toplayerAnimationDatainto the scheduled main-thread task so it’s single-threaded.