Add BeaconEffectEvent

This commit is contained in:
Byteflux 2016-03-02 23:30:53 -06:00
parent c9cf82340d
commit adb6c35b17

View File

@ -1,17 +1,25 @@
--- a/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BeaconBlockEntity.java
@@ -45,6 +45,10 @@
@@ -1,5 +1,6 @@
package net.minecraft.world.level.block.entity;
+import com.destroystokyo.paper.event.block.BeaconEffectEvent;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.Collection;
@@ -45,6 +46,11 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.phys.AABB;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.potion.CraftPotionUtil;
+import org.bukkit.potion.PotionEffect;
+// CraftBukkit end
public class BeaconBlockEntity extends BlockEntity implements MenuProvider, Nameable {
@@ -71,6 +75,15 @@
@@ -71,7 +77,16 @@
public Component name;
public LockCode lockKey;
private final ContainerData dataAccess;
@ -19,15 +27,16 @@
+ public PotionEffect getPrimaryEffect() {
+ return (this.primaryPower != null) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.primaryPower, BeaconBlockEntity.getLevel(this.levels), BeaconBlockEntity.getAmplification(this.levels, this.primaryPower, this.secondaryPower), true, true)) : null;
+ }
+
+ public PotionEffect getSecondaryEffect() {
+ return (BeaconBlockEntity.hasSecondaryEffect(this.levels, this.primaryPower, this.secondaryPower)) ? CraftPotionUtil.toBukkit(new MobEffectInstance(this.secondaryPower, BeaconBlockEntity.getLevel(this.levels), BeaconBlockEntity.getAmplification(this.levels, this.primaryPower, this.secondaryPower), true, true)) : null;
+ }
+ // CraftBukkit end
+
@Nullable
static Holder<MobEffect> filterEffect(@Nullable Holder<MobEffect> effect) {
@@ -251,39 +264,78 @@
return BeaconBlockEntity.VALID_EFFECTS.contains(effect) ? effect : null;
@@ -251,39 +266,86 @@
super.setRemoved();
}
@ -68,16 +77,25 @@
+ }
+ }
+
+ private static void applyEffect(List list, @Nullable Holder<MobEffect> holder, int j, int b0) {
+ {
+ private static void applyEffect(List list, @Nullable Holder<MobEffect> holder, int j, int b0, boolean isPrimary, BlockPos worldPosition) { // Paper - BeaconEffectEvent
+ if (!list.isEmpty()) { // Paper - BeaconEffectEvent
Iterator iterator = list.iterator();
Player entityhuman;
+ // Paper start - BeaconEffectEvent
+ org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(((Player) list.get(0)).level(), worldPosition);
+ PotionEffect effect = CraftPotionUtil.toBukkit(new MobEffectInstance(holder, j, b0, true, true));
+ // Paper end - BeaconEffectEvent
while (iterator.hasNext()) {
entityhuman = (Player) iterator.next();
- entityhuman = (Player) iterator.next();
- entityhuman.addEffect(new MobEffectInstance(primaryEffect, j, b0, true, true));
+ entityhuman.addEffect(new MobEffectInstance(holder, j, b0, true, true), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
+ // Paper start - BeaconEffectEvent
+ entityhuman = (ServerPlayer) iterator.next();
+ BeaconEffectEvent event = new BeaconEffectEvent(block, effect, (org.bukkit.entity.Player) entityhuman.getBukkitEntity(), isPrimary);
+ if (CraftEventFactory.callEvent(event).isCancelled()) continue;
+ entityhuman.addEffect(new MobEffectInstance(CraftPotionUtil.fromBukkit(event.getEffect())), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.BEACON);
+ // Paper end - BeaconEffectEvent
}
+ }
+ }
@ -107,10 +125,10 @@
+ int j = BeaconBlockEntity.getLevel(beaconLevel);
+ List list = BeaconBlockEntity.getHumansInRange(world, pos, beaconLevel);
+
+ BeaconBlockEntity.applyEffect(list, primaryEffect, j, b0);
+ BeaconBlockEntity.applyEffect(list, primaryEffect, j, b0, true, pos); // Paper - BeaconEffectEvent
+
+ if (BeaconBlockEntity.hasSecondaryEffect(beaconLevel, primaryEffect, secondaryEffect)) {
+ BeaconBlockEntity.applyEffect(list, secondaryEffect, j, 0);
+ BeaconBlockEntity.applyEffect(list, secondaryEffect, j, 0, false, pos); // Paper - BeaconEffectEvent
+ }
+ }
+
@ -120,7 +138,7 @@
public static void playSound(Level world, BlockPos pos, SoundEvent sound) {
world.playSound((Player) null, pos, sound, SoundSource.BLOCKS, 1.0F, 1.0F);
}
@@ -316,7 +368,7 @@
@@ -316,7 +378,7 @@
if (nbt.contains(key, 8)) {
ResourceLocation minecraftkey = ResourceLocation.tryParse(nbt.getString(key));
@ -129,7 +147,7 @@
} else {
return null;
}
@@ -327,6 +379,7 @@
@@ -327,6 +389,7 @@
super.loadAdditional(nbt, registries);
this.primaryPower = BeaconBlockEntity.loadEffect(nbt, "primary_effect");
this.secondaryPower = BeaconBlockEntity.loadEffect(nbt, "secondary_effect");