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

Prevent duplicate raider in RaidSpawnWaveEvent list #12040

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,20 @@
this.stop();
return;
}
@@ -491,6 +_,10 @@
@@ -486,7 +_,7 @@

private void spawnGroup(BlockPos pos) {
boolean flag = false;
- int i = this.groupsSpawned + 1;
+ int i = this.groupsSpawned + 1; final int wave = i; // Paper - OBFHELPER
this.totalHealth = 0.0F;
DifficultyInstance currentDifficultyAt = this.level.getCurrentDifficultyAt(pos);
boolean shouldSpawnBonusGroup = this.shouldSpawnBonusGroup();

+ // CraftBukkit start
+ Raider leader = null;
+ List<Raider> raiders = new java.util.ArrayList<>();
+ // CraftBukkit end
for (Raid.RaiderType raiderType : Raid.RaiderType.VALUES) {
int i1 = this.getDefaultNumSpawns(raiderType, i, shouldSpawnBonusGroup)
+ this.getPotentialBonusSpawns(raiderType, this.random, i, currentDifficultyAt, shouldSpawnBonusGroup);
@@ -506,9 +_,11 @@
raider.setPatrolLeader(true);
this.setLeader(i, raider);
flag = true;
+ leader = raider; // CraftBukkit
}

this.joinRaid(i, raider, pos, false);
+ raiders.add(raider); // CraftBukkit
if (raiderType.entityType == EntityType.RAVAGER) {
Raider raider1 = null;
if (i == this.getNumGroups(Difficulty.NORMAL)) {
@@ -526,6 +_,7 @@
this.joinRaid(i, raider1, pos, false);
raider1.moveTo(pos, 0.0F, 0.0F);
raider1.startRiding(raider);
+ raiders.add(raider); // CraftBukkit
}
}
}
@@ -535,6 +_,7 @@
this.groupsSpawned++;
this.updateBossbar();
this.setDirty();
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidSpawnWaveEvent(this, leader, raiders); // CraftBukkit
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidSpawnWaveEvent(this, java.util.Objects.requireNonNull(this.getLeader(wave)), this.groupRaiderMap.get(wave)); // CraftBukkit
}

public void joinRaid(int wave, Raider raider, @Nullable BlockPos pos, boolean isRecruited) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -87,7 +88,6 @@
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.entity.CraftRaider;
import org.bukkit.craftbukkit.entity.CraftSpellcaster;
import org.bukkit.craftbukkit.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
Expand Down Expand Up @@ -2015,14 +2015,14 @@ public static void callRaidStopEvent(Raid raid, RaidStopEvent.Reason reason) {
Bukkit.getPluginManager().callEvent(event);
}

public static void callRaidSpawnWaveEvent(Raid raid, net.minecraft.world.entity.raid.Raider leader, List<net.minecraft.world.entity.raid.Raider> raiders) {
Raider craftLeader = (CraftRaider) leader.getBukkitEntity();
List<Raider> craftRaiders = new ArrayList<>();
for (net.minecraft.world.entity.raid.Raider entityRaider : raiders) {
craftRaiders.add((Raider) entityRaider.getBukkitEntity());
public static void callRaidSpawnWaveEvent(Raid raid, net.minecraft.world.entity.raid.Raider leader, Set<net.minecraft.world.entity.raid.Raider> raiders) {
Raider bukkitLeader = (Raider) leader.getBukkitEntity();
List<Raider> bukkitRaiders = new ArrayList<>(raiders.size());
for (net.minecraft.world.entity.raid.Raider raider : raiders) {
bukkitRaiders.add((Raider) raider.getBukkitEntity());
}
RaidSpawnWaveEvent event = new RaidSpawnWaveEvent(new CraftRaid(raid), raid.getLevel().getWorld(), craftLeader, craftRaiders);
Bukkit.getPluginManager().callEvent(event);
RaidSpawnWaveEvent event = new RaidSpawnWaveEvent(new CraftRaid(raid), raid.getLevel().getWorld(), bukkitLeader, bukkitRaiders);
event.callEvent();
}

public static LootGenerateEvent callLootGenerateEvent(Container inventory, LootTable lootTable, LootContext lootInfo, List<ItemStack> loot, boolean plugin) {
Expand Down
Loading