--- a/net/minecraft/world/entity/raid/PersistentRaid.java
+++ b/net/minecraft/world/entity/raid/PersistentRaid.java
@@ -115,11 +115,23 @@
 
                 Raid raid = this.getOrCreateRaid(entityplayer.serverLevel(), blockposition2);
 
+                /* CraftBukkit - moved down
                 if (!raid.isStarted() && !this.raidMap.containsKey(raid.getId())) {
                     this.raidMap.put(raid.getId(), raid);
                 }
+                */
 
-                if (!raid.isStarted() || raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel()) {
+                if (!raid.isStarted() || (raid.isInProgress() && raid.getRaidOmenLevel() < raid.getMaxRaidOmenLevel())) { // CraftBukkit - fixed a bug with raid: players could add up Bad Omen level even when the raid had finished
+                    // CraftBukkit start
+                    if (!org.bukkit.craftbukkit.event.CraftEventFactory.callRaidTriggerEvent(raid, entityplayer)) {
+                        entityplayer.removeEffect(net.minecraft.world.effect.MobEffects.RAID_OMEN);
+                        return null;
+                    }
+
+                    if (!raid.isStarted() && !this.raidMap.containsKey(raid.getId())) {
+                        this.raidMap.put(raid.getId(), raid);
+                    }
+                    // CraftBukkit end
                     raid.absorbRaidOmen(entityplayer);
                 }
 
