Fix slime spawner exploit (#5089)

* Fix slime spawner exploit

* Move slime/magmacube into a constant
This commit is contained in:
Ineusia 2024-09-28 16:26:22 -04:00 committed by GitHub
parent 5c68a176e5
commit d5c4bebfad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,9 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
import java.util.Arrays;
import java.util.List;
import static com.gmail.nossr50.util.MobMetadataUtils.*; import static com.gmail.nossr50.util.MobMetadataUtils.*;
public class EntityListener implements Listener { public class EntityListener implements Listener {
@ -55,6 +58,7 @@ public class EntityListener implements Listener {
* check if a {@link Player} has a {@link Trident} enchanted with "Piercing". * check if a {@link Player} has a {@link Trident} enchanted with "Piercing".
*/ */
private final NamespacedKey piercingEnchantment = NamespacedKey.minecraft("piercing"); private final NamespacedKey piercingEnchantment = NamespacedKey.minecraft("piercing");
private final List<EntityType> transformableEntities = Arrays.asList(EntityType.SLIME, EntityType.MAGMA_CUBE);
public EntityListener(final mcMMO pluginRef) { public EntityListener(final mcMMO pluginRef) {
this.pluginRef = pluginRef; this.pluginRef = pluginRef;
@ -72,6 +76,11 @@ public class EntityListener implements Listener {
} }
} }
} }
// Clear the original slime/magma cubes metadata - it's dead.
if (transformableEntities.contains(livingEntity.getType())) {
mcMMO.getTransientMetadataTools().cleanLivingEntityMetadata(livingEntity);
}
} }
} }
@ -652,7 +661,14 @@ public class EntityListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
public void onEntityDeathLowest(EntityDeathEvent event) { 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);
} }
/** /**