Skip to content

Commit 6aa085b

Browse files
Doc94lynxplayOwen1212055
authored
Raid max Groups configurable by API (#12896)
Co-authored-by: Bjarne Koll <[email protected]> Co-authored-by: Owen1212055 <[email protected]>
1 parent 3f07f02 commit 6aa085b

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

build-data/paper.at

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ public net.minecraft.world.entity.projectile.hurtingprojectile.windcharge.Breeze
486486
public net.minecraft.world.entity.projectile.hurtingprojectile.windcharge.WindCharge explode(Lnet/minecraft/world/phys/Vec3;)V
487487
public net.minecraft.world.entity.projectile.throwableitemprojectile.ThrowableItemProjectile getDefaultItem()Lnet/minecraft/world/item/Item;
488488
public net.minecraft.world.entity.raid.Raid heroesOfTheVillage
489-
public net.minecraft.world.entity.raid.Raid numGroups
490489
public net.minecraft.world.entity.raid.Raid raidEvent
491490
public net.minecraft.world.entity.raid.Raid raidOmenLevel
492491
public net.minecraft.world.entity.raid.Raid ticksActive
@@ -765,6 +764,7 @@ public-f net.minecraft.world.entity.Mob goalSelector
765764
public-f net.minecraft.world.entity.Mob targetSelector
766765
public-f net.minecraft.world.entity.ai.attributes.RangedAttribute maxValue
767766
public-f net.minecraft.world.entity.player.Player gameProfile
767+
public-f net.minecraft.world.entity.raid.Raid numGroups
768768
public-f net.minecraft.world.inventory.AbstractContainerMenu dataSlots
769769
public-f net.minecraft.world.inventory.AbstractContainerMenu lastSlots
770770
public-f net.minecraft.world.inventory.AbstractContainerMenu remoteDataSlots

paper-api/src/main/java/org/bukkit/Raid.java

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import java.util.List;
44
import java.util.Set;
55
import java.util.UUID;
6+
import org.bukkit.boss.BossBar;
67
import org.bukkit.entity.Raider;
7-
import org.jetbrains.annotations.NotNull;
8+
import org.bukkit.persistence.PersistentDataHolder;
9+
import org.jspecify.annotations.NullMarked;
810

911
/**
1012
* Represents a raid event.
1113
*/
12-
public interface Raid extends org.bukkit.persistence.PersistentDataHolder { // Paper
14+
@NullMarked
15+
public interface Raid extends PersistentDataHolder {
1316

1417
/**
1518
* Get whether this raid started.
@@ -48,7 +51,6 @@ public interface Raid extends org.bukkit.persistence.PersistentDataHolder { // P
4851
*
4952
* @return location
5053
*/
51-
@NotNull
5254
Location getLocation();
5355

5456
/**
@@ -59,7 +61,6 @@ public interface Raid extends org.bukkit.persistence.PersistentDataHolder { // P
5961
*
6062
* @return Raids status
6163
*/
62-
@NotNull
6364
RaidStatus getStatus();
6465

6566
/**
@@ -86,6 +87,16 @@ public interface Raid extends org.bukkit.persistence.PersistentDataHolder { // P
8687
*/
8788
int getTotalWaves();
8889

90+
/**
91+
* Sets the number of waves in this raid.
92+
*
93+
* @param totalWaves number of waves
94+
* @throws IllegalArgumentException if totalWaves is negative or zero
95+
* @throws IllegalArgumentException if totalWaves is larger than 7, which is the most waves a vanilla raid can have.
96+
* @throws IllegalArgumentException if the totalWaves is less than {@link #getSpawnedGroups()}
97+
*/
98+
void setTotalWaves(int totalWaves);
99+
89100
/**
90101
* Gets the sum of all raider's health.
91102
*
@@ -98,21 +109,36 @@ public interface Raid extends org.bukkit.persistence.PersistentDataHolder { // P
98109
*
99110
* @return a set of unique ids
100111
*/
101-
@NotNull
102112
Set<UUID> getHeroes();
103113

104114
/**
105115
* Gets all remaining {@link Raider} in the present wave.
106116
*
107117
* @return a list of current raiders
108118
*/
109-
@NotNull
110119
List<Raider> getRaiders();
111120

121+
/**
122+
* Gets the id of this raid.
123+
*
124+
* @return the raid id
125+
* @deprecated Raid identifiers are magic internal values and may or may not be present.
126+
* -1 is returned for raids without an assigned id.
127+
*/
128+
@Deprecated(forRemoval = true, since = "1.21.5")
129+
int getId();
130+
131+
/**
132+
* Get the boss bar to be displayed for this raid.
133+
*
134+
* @return the boss bar
135+
*/
136+
BossBar getBossBar();
137+
112138
/**
113139
* Represents the status of a {@link Raid}.
114140
*/
115-
public enum RaidStatus {
141+
enum RaidStatus {
116142

117143
/**
118144
* The raid is in progress.
@@ -131,23 +157,4 @@ public enum RaidStatus {
131157
*/
132158
STOPPED;
133159
}
134-
135-
// Paper start
136-
/**
137-
* Gets the id of this raid.
138-
*
139-
* @return the raid id
140-
* @deprecated Raid identifiers are magic internal values and may or may not be present.
141-
* -1 is returned for raids without an assigned id.
142-
*/
143-
@Deprecated(forRemoval = true, since = "1.21.5")
144-
int getId();
145-
146-
/**
147-
* Get the boss bar to be displayed for this raid.
148-
*
149-
* @return the boss bar
150-
*/
151-
org.bukkit.boss.@NotNull BossBar getBossBar();
152-
// Paper end
153160
}

paper-server/src/main/java/org/bukkit/craftbukkit/CraftRaid.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import java.util.List;
77
import java.util.Set;
88
import java.util.UUID;
9-
import java.util.function.Function;
109
import net.minecraft.core.BlockPos;
1110
import net.minecraft.world.level.Level;
1211
import org.bukkit.Location;
1312
import org.bukkit.Raid;
13+
import org.bukkit.boss.BossBar;
14+
import org.bukkit.craftbukkit.boss.CraftBossBar;
1415
import org.bukkit.craftbukkit.util.CraftLocation;
1516
import org.bukkit.entity.Raider;
17+
import org.bukkit.persistence.PersistentDataContainer;
1618

1719
public final class CraftRaid implements Raid {
1820

@@ -80,6 +82,14 @@ public int getTotalWaves() {
8082
return this.handle.numGroups;
8183
}
8284

85+
@Override
86+
public void setTotalWaves(int waves) {
87+
Preconditions.checkArgument(waves > 0, "Total waves must be greater than 0");
88+
Preconditions.checkArgument(waves <= 7, "Total waves must not be greater than 7");
89+
Preconditions.checkArgument(waves >= this.getSpawnedGroups(), "Total waves must be greater than or equal to the current spawned groups (%s)", this.getSpawnedGroups());
90+
this.handle.numGroups = waves;
91+
}
92+
8393
@Override
8494
public float getTotalHealth() {
8595
return this.handle.getHealthOfLivingRaiders();
@@ -92,12 +102,7 @@ public Set<UUID> getHeroes() {
92102

93103
@Override
94104
public List<Raider> getRaiders() {
95-
return this.handle.getRaiders().stream().map(new Function<net.minecraft.world.entity.raid.Raider, Raider>() {
96-
@Override
97-
public Raider apply(net.minecraft.world.entity.raid.Raider entityRaider) {
98-
return (Raider) entityRaider.getBukkitEntity();
99-
}
100-
}).collect(ImmutableList.toImmutableList());
105+
return this.handle.getRaiders().stream().map(entityRaider -> (Raider) entityRaider.getBukkitEntity()).collect(ImmutableList.toImmutableList());
101106
}
102107

103108
public net.minecraft.world.entity.raid.Raid getHandle() {
@@ -110,20 +115,20 @@ public int getId() {
110115
}
111116

112117
@Override
113-
public org.bukkit.boss.BossBar getBossBar() {
114-
return new org.bukkit.craftbukkit.boss.CraftBossBar(this.handle.raidEvent);
118+
public BossBar getBossBar() {
119+
return new CraftBossBar(this.handle.raidEvent);
115120
}
116121

117122
@Override
118-
public org.bukkit.persistence.PersistentDataContainer getPersistentDataContainer() {
123+
public PersistentDataContainer getPersistentDataContainer() {
119124
return this.handle.persistentDataContainer;
120125
}
121126

122127
@Override
123128
public boolean equals(final Object o) {
124129
if (this == o) return true;
125130
if (o == null || this.getClass() != o.getClass()) return false;
126-
final org.bukkit.craftbukkit.CraftRaid craftRaid = (org.bukkit.craftbukkit.CraftRaid) o;
131+
final CraftRaid craftRaid = (CraftRaid) o;
127132
return this.handle.equals(craftRaid.handle);
128133
}
129134

0 commit comments

Comments
 (0)