Skip to content
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 slime spawner exploit #5089

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/java/com/gmail/nossr50/listeners/EntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource;

import java.util.Arrays;
import java.util.List;

import static com.gmail.nossr50.util.MobMetadataUtils.*;

public class EntityListener implements Listener {
Expand All @@ -55,6 +58,7 @@ public class EntityListener implements Listener {
* check if a {@link Player} has a {@link Trident} enchanted with "Piercing".
*/
private final NamespacedKey piercingEnchantment = NamespacedKey.minecraft("piercing");
private final List<EntityType> transformableEntities = Arrays.asList(EntityType.SLIME, EntityType.MAGMA_CUBE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be static as well, I'll make the change after I merge.


public EntityListener(final mcMMO pluginRef) {
this.pluginRef = pluginRef;
Expand All @@ -72,6 +76,11 @@ public void onEntityTransform(EntityTransformEvent event) {
}
}
}

// Clear the original slime/magma cubes metadata - it's dead.
if (transformableEntities.contains(livingEntity.getType())) {
mcMMO.getTransientMetadataTools().cleanLivingEntityMetadata(livingEntity);
}
}
}

Expand Down Expand Up @@ -652,7 +661,14 @@ else if (livingEntity instanceof Tameable pet) {
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDeathLowest(EntityDeathEvent event) {
mcMMO.getTransientMetadataTools().cleanLivingEntityMetadata(event.getEntity());
LivingEntity entity = event.getEntity();

// Clear metadata for Slimes/Magma Cubes after transformation events take place, otherwise small spawned slimes will not have any tags
if (transformableEntities.contains(entity.getType())) {
return;
}

mcMMO.getTransientMetadataTools().cleanLivingEntityMetadata(entity);
}

/**
Expand Down
Loading