Paper/nms-patches/Raid.patch
2019-12-11 09:00:00 +11:00

138 lines
6.1 KiB
Diff

--- a/net/minecraft/server/Raid.java
+++ b/net/minecraft/server/Raid.java
@@ -114,6 +114,12 @@
return this.status == Raid.Status.LOSS;
}
+ // CraftBukkit start
+ public boolean isInProgress() {
+ return this.status == Status.ONGOING;
+ }
+ // CraftBukkit end
+
public World getWorld() {
return this.world;
}
@@ -189,6 +195,7 @@
this.active = this.world.isLoaded(this.center);
if (this.world.getDifficulty() == EnumDifficulty.PEACEFUL) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.PEACE); // CraftBukkit
this.stop();
return;
}
@@ -208,13 +215,16 @@
if (!this.world.b_(this.center)) {
if (this.groupsSpawned > 0) {
this.status = Raid.Status.LOSS;
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidFinishEvent(this, new java.util.ArrayList<>()); // CraftBukkit
} else {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.NOT_IN_VILLAGE); // CraftBukkit
this.stop();
}
}
++this.ticksActive;
if (this.ticksActive >= 48000L) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.TIMEOUT); // CraftBukkit
this.stop();
return;
}
@@ -288,6 +298,7 @@
}
if (j > 3) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.UNSPAWNABLE); // CraftBukkit
this.stop();
break;
}
@@ -300,6 +311,7 @@
this.status = Raid.Status.VICTORY;
Iterator iterator = this.heroes.iterator();
+ List<org.bukkit.entity.Player> winners = new java.util.ArrayList<>(); // CraftBukkit
while (iterator.hasNext()) {
UUID uuid = (UUID) iterator.next();
Entity entity = this.world.getEntity(uuid);
@@ -313,9 +325,11 @@
entityplayer.a(StatisticList.RAID_WIN);
CriterionTriggers.H.a(entityplayer);
+ winners.add(entityplayer.getBukkitEntity()); // CraftBukkit
}
}
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidFinishEvent(this, winners); // CraftBukkit
}
}
@@ -323,6 +337,7 @@
} else if (this.a()) {
++this.x;
if (this.x >= 600) {
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidStopEvent(this, org.bukkit.event.raid.RaidStopEvent.Reason.FINISHED); // CraftBukkit
this.stop();
return;
}
@@ -457,6 +472,10 @@
Raid.Wave[] araid_wave = Raid.Wave.f;
int j = araid_wave.length;
+ // CraftBukkit start
+ EntityRaider leader = null;
+ List<EntityRaider> raiders = new java.util.ArrayList<>();
+ // CraftBukkit end
for (int k = 0; k < j; ++k) {
Raid.Wave raid_wave = araid_wave[k];
int l = this.a(raid_wave, i, flag1) + this.a(raid_wave, this.random, i, difficultydamagescaler, flag1);
@@ -469,9 +488,11 @@
entityraider.setPatrolLeader(true);
this.a(i, entityraider);
flag = true;
+ leader = entityraider; // CraftBukkit
}
this.a(i, entityraider, blockposition, false);
+ raiders.add(entityraider); // CraftBukkit
if (raid_wave.g == EntityTypes.RAVAGER) {
EntityRaider entityraider1 = null;
@@ -490,6 +511,7 @@
this.a(i, entityraider1, blockposition, false);
entityraider1.setPositionRotation(blockposition, 0.0F, 0.0F);
entityraider1.startRiding(entityraider);
+ raiders.add(entityraider); // CraftBukkit
}
}
}
@@ -499,6 +521,7 @@
++this.groupsSpawned;
this.updateProgress();
this.H();
+ org.bukkit.craftbukkit.event.CraftEventFactory.callRaidSpawnWaveEvent(this, leader, raiders); // CraftBukkit
}
public void a(int i, EntityRaider entityraider, @Nullable BlockPosition blockposition, boolean flag) {
@@ -514,7 +537,7 @@
entityraider.prepare(this.world, this.world.getDamageScaler(blockposition), EnumMobSpawn.EVENT, (GroupDataEntity) null, (NBTTagCompound) null);
entityraider.a(i, false);
entityraider.onGround = true;
- this.world.addEntity(entityraider);
+ this.world.addEntity(entityraider, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.RAID); // CraftBukkit
}
}
@@ -760,6 +783,12 @@
this.heroes.add(entity.getUniqueID());
}
+ // CraftBukkit start - a method to get all raiders
+ public java.util.Collection<EntityRaider> getRaiders() {
+ return this.raiders.values().stream().flatMap(Set::stream).collect(java.util.stream.Collectors.toSet());
+ }
+ // CraftBukkit end
+
static enum Wave {
VINDICATOR(EntityTypes.VINDICATOR, new int[]{0, 0, 2, 0, 1, 4, 2, 5}), EVOKER(EntityTypes.EVOKER, new int[]{0, 0, 0, 0, 0, 1, 1, 2}), PILLAGER(EntityTypes.PILLAGER, new int[]{0, 4, 3, 3, 4, 4, 4, 2}), WITCH(EntityTypes.WITCH, new int[]{0, 0, 0, 0, 3, 0, 0, 1}), RAVAGER(EntityTypes.RAVAGER, new int[]{0, 0, 0, 1, 0, 1, 0, 2});