Jump to content

Recommended Posts

Posted

I'm trying to make it so that when an effect is cleared from the player, a different effect is given to them instead (eg: if speed is cleared they get slowness instead). This works fine when using the /effect clear minecraft:speed command, but if I use the basic /effect clear command, it throws an error, saying that there is a concurrent modification exception. I assume this has to do with the fact that /effect clear is wiping the entire effect instance rather than just a single effect, and it doesn't like the fact that I am trying to add a new effect while it is still trying to clear the old effects. Does anyone know a way that I could get around this problem?

Posted

The issue happens because you're modifying the player's effects list while it's still being cleared. When you run /effect clear, Minecraft is iterating over and removing all active effects. If you try to add a new one during that process (inside onEffectRemoved), it throws a ConcurrentModificationException. Instead of applying the new effect immediately inside onEffectRemoved, store it in a temporary list, and then apply it safely during the next tick (in a tick event). That way, the original clearing process finishes before you add anything new.

that is 1. In onEffectRemoved: just remember which effect to apply next. 2. In tick: apply the effect from the stored list.

More likely this prevents any conflict and works even when all effects are cleared at once 

I hope it helped.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.