package net.simpvp.Misc;

import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityShootBowEvent;

import net.minecraft.server.v1_16_R3.Entity;
import net.minecraft.server.v1_16_R3.NBTTagCompound;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity;

/**
 * Removes shooter info from arrows shot by players.
 *
 * This is to mitigate an exploit in which shot arrows can leak their shooters
 * information, even long after the fact.
 */
public class ArrowOwner implements Listener {

	@EventHandler
	public void onShootBow(EntityShootBowEvent event) {
		if (!(event.getEntity() instanceof Player)) {
			return;
		}

		Projectile p;
		if (event.getProjectile() instanceof Projectile) {
			p = (Projectile) event.getProjectile();
		} else {
			Misc.instance.getLogger().warning("Shot non-projectile");
			return;
		}

		Entity e = ((CraftEntity) p).getHandle();
		NBTTagCompound nbt = new NBTTagCompound();
		e.save(nbt);

		// Set the value to 0 instead of removing the entry, because it
		// seems to do a merge of the maps when calling load.
		int[] owner = nbt.getIntArray("Owner");
		for (int i = 0; i < owner.length; i++) {
			owner[i] = 0;
		}
		nbt.setIntArray("Owner", owner);
		e.load(nbt);
	}
}

@@ -212,16 +212,157 @@
 owEvent;
+%0Aimport org.bukkit.event.entity.ProjectileHitEvent;%0Aimport org.bukkit.event.world.ChunkLoadEvent;%0Aimport org.bukkit.scheduler.BukkitRunnable;
 %0A%0Aimport
@@ -744,17 +744,16 @@
 tener %7B%0A
-%0A
 %09@EventH
@@ -778,153 +778,413 @@
 d on
-ShootBow(EntityShootBowEvent event) %7B%0A%09%09if (!(event.getEntity() instanceof Player)) %7B%0A%09%09%09return;%0A%09%09%7D%0A%0A%09%09Projectile p;%0A%09%09if (event.getProjectile()
+ProjectileHit(ProjectileHitEvent event) %7B%0A%09%09final Projectile p = event.getEntity();%0A%09%09new BukkitRunnable() %7B%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09%09%09%09remove_owner_info(p);%0A%0A%09%09%09%7D%0A%09%09%7D.runTaskLater(Misc.instance, 1L);%0A%0A%09%7D%0A%0A%09@EventHandler%0A%09public void onChunkLoad(ChunkLoadEvent event) %7B%0A%09%09if (event.isNewChunk()) %7B%0A%09%09%09return;%0A%09%09%7D%0A%0A%09%09for (org.bukkit.entity.Entity e : event.getChunk().getEntities()) %7B%0A%09%09%09if (e
  ins
@@ -1212,34 +1212,28 @@
 %0A%09%09%09
-p = (Projectile) event.get
+%09remove_owner_info((
 Proj
@@ -1242,99 +1242,74 @@
 tile
-(
+) e
 );%0A%09%09
-%7D else %7B%0A%09%09%09Misc.instance.getLogger().warning(%22Shot non-projectile%22);%0A%09%09%09return;%0A%09%09%7D%0A
+%09%7D%0A%09%09%7D%0A%09%7D%0A%0A%09private void remove_owner_info(Projectile p) %7B
 %0A%09%09E

Make the arrow owner fix less disruptive