Skip to content
Permalink
Browse files

User paper firework tracking.

  • Loading branch information...
wizjany committed Jul 28, 2019
1 parent c5bfdcb commit 11a1ac674218ecd289661bf8bd08f7f998d1a2a4
@@ -22,15 +22,27 @@
import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import com.sk89q.worldguard.bukkit.internal.WGMetadata;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.*;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Vehicle;
import org.bukkit.metadata.Metadatable;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.UUID;

import static com.google.common.base.Preconditions.checkNotNull;

@@ -249,6 +261,14 @@ private void addAll(@Nullable Object... element) {
addAll(((TNTPrimed) o).getSource());
} else if (o instanceof Projectile) {
addAll(((Projectile) o).getShooter());
} else if (o instanceof Firework && PaperLib.isPaper()) {
UUID spawningUUID = ((Firework) o).getSpawningEntity();
if (spawningUUID != null) {
Entity spawningEntity = Bukkit.getEntity(spawningUUID);
if (spawningEntity != null) {
addAll(spawningEntity);
}
}
} else if (o instanceof Vehicle) {
addAll(((Vehicle) o).getPassengers());
} else if (o instanceof AreaEffectCloud) {
@@ -31,18 +31,22 @@
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.regions.RegionQuery;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;

import java.util.UUID;
import java.util.function.Predicate;

public class RegionFlagsListener extends AbstractListener {
@@ -142,7 +146,17 @@ public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof EntityDamageByEntityEvent) {
Entity damager = (((EntityDamageByEntityEvent) event)).getDamager();
if (damager.getType() == EntityType.FIREWORK) {
if (!query.testState(BukkitAdapter.adapt(entity.getLocation()), (RegionAssociable) null, Flags.FIREWORK_DAMAGE)) {
RegionAssociable associable = null;
if (PaperLib.isPaper()) {
UUID spawning = ((Firework) damager).getSpawningEntity();
if (spawning != null) {
Player player = Bukkit.getPlayer(spawning);
if (player != null) {
associable = WorldGuardPlugin.inst().wrapPlayer(player);
}
}
}
if (!query.testState(BukkitAdapter.adapt(entity.getLocation()), associable, Flags.FIREWORK_DAMAGE)) {
event.setCancelled(true);
return;
}

0 comments on commit 11a1ac6

Please sign in to comment.
You can’t perform that action at this time.