From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: jmp <jasonpenilla2@me.com>
Date: Thu, 27 Aug 2020 13:48:52 -0700
Subject: [PATCH] Raid cooldown setting


diff --git a/src/main/java/net/minecraft/world/entity/raid/PersistentRaid.java b/src/main/java/net/minecraft/world/entity/raid/PersistentRaid.java
index c939ca087af4588e14669a2d53d7c116dcb59f16..11271762dcf5783c3179de1afc6a882c5330b4dd 100644
--- a/src/main/java/net/minecraft/world/entity/raid/PersistentRaid.java
+++ b/src/main/java/net/minecraft/world/entity/raid/PersistentRaid.java
@@ -27,6 +27,7 @@ import net.minecraft.world.phys.Vec3D;
 
 public class PersistentRaid extends PersistentBase {
 
+    public final Map<java.util.UUID, Integer> playerCooldowns = new java.util.HashMap<>(); // Purpur
     public final Map<Integer, Raid> raids = Maps.newHashMap();
     private final WorldServer b;
     private int c;
@@ -45,6 +46,17 @@ public class PersistentRaid extends PersistentBase {
 
     public void a() {
         ++this.d;
+        // Purpur start
+        if (b.purpurConfig.raidCooldownSeconds != 0 && this.d % 20 == 0) {
+            com.google.common.collect.ImmutableMap.copyOf(playerCooldowns).forEach((id, i) -> {
+                if (i < 1) {
+                    playerCooldowns.remove(id);
+                } else {
+                    playerCooldowns.put(id, i - 1);
+                }
+            });
+        }
+        // Purpur end
         Iterator iterator = this.raids.values().iterator();
 
         while (iterator.hasNext()) {
@@ -128,10 +140,15 @@ public class PersistentRaid extends PersistentBase {
 
                 if (flag) {
                     // CraftBukkit start
-                    if (!org.bukkit.craftbukkit.event.CraftEventFactory.callRaidTriggerEvent(raid, entityplayer)) {
+                    if ((b.purpurConfig.raidCooldownSeconds != 0 && playerCooldowns.containsKey(entityplayer.getUniqueID())) || !org.bukkit.craftbukkit.event.CraftEventFactory.callRaidTriggerEvent(raid, entityplayer)) { // Purpur
                         entityplayer.removeEffect(MobEffects.BAD_OMEN);
                         return null;
                     }
+                    // Purpur start
+                    if (b.purpurConfig.raidCooldownSeconds != 0) {
+                        playerCooldowns.put(entityplayer.getUniqueID(), b.purpurConfig.raidCooldownSeconds);
+                    }
+                    // Purpur end
 
                     if (!this.raids.containsKey(raid.getId())) {
                         this.raids.put(raid.getId(), raid);
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index b60ac4576578f9dc95b66ad2932b046f7f50317e..847975c3c2309633e1505b9ee37d9d7ba9019f0f 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -173,6 +173,7 @@ public class PurpurWorldConfig {
     public boolean milkCuresBadOmen = true;
     public double tridentLoyaltyVoidReturnHeight = 0.0D;
     public double voidDamageHeight = -64.0D;
+    public int raidCooldownSeconds = 0;
     private void miscGameplayMechanicsSettings() {
         useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending);
         boatEjectPlayersOnLand = getBoolean("gameplay-mechanics.boat.eject-players-on-land", boatEjectPlayersOnLand);
@@ -182,6 +183,7 @@ public class PurpurWorldConfig {
         milkCuresBadOmen = getBoolean("gameplay-mechanics.milk-cures-bad-omen", milkCuresBadOmen);
         tridentLoyaltyVoidReturnHeight = getDouble("gameplay-mechanics.trident-loyalty-void-return-height", tridentLoyaltyVoidReturnHeight);
         voidDamageHeight = getDouble("gameplay-mechanics.void-damage-height", voidDamageHeight);
+        raidCooldownSeconds = getInt("gameplay-mechanics.raid-cooldown-seconds", raidCooldownSeconds);
     }
 
     public boolean catSpawning;
