<commit_before>package de.domisum.auxiliumapi.util.bukkit;

import de.domisum.auxiliumapi.util.java.ReflectionUtil;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class PlayerUtil
{

	// MANIPULATION
	public static void clear(Player player)
	{
		player.getInventory().clear();
		player.getInventory().setArmorContents(null);

		player.setLevel(0);
		player.setExp(0);

		player.setHealth(player.getMaxHealth());
		player.setSaturation(5);
		player.setFoodLevel(20);

		for(PotionEffect pe : player.getActivePotionEffects())
			player.removePotionEffect(pe.getType());

		removeArrows(player);
	}

	public static void removeArrows(Player player)
	{
		// reflection makes this plugin compatible with multiple versions

		try
		{
			// reflection code for this:
			// ((CraftPlayer) player).getHandle().k(0);

			Class<?> craftPlayerClazz = Class.forName(ReflectionUtil.getCBPath()+"entity.CraftPlayer");
			Method getHandle = craftPlayerClazz.getMethod("getHandle");
			Object entityPlayer = getHandle.invoke(player);

			Method setArrows = entityPlayer.getClass().getMethod("k", int.class);
			setArrows.invoke(entityPlayer, 0);
		}
		catch(ClassNotFoundException|NoSuchMethodException|SecurityException|IllegalArgumentException|IllegalAccessException|InvocationTargetException reflectionException)
		{
			reflectionException.printStackTrace();
		}
	}

	public static void respawn(Player player)
	{
		try
		{
			// reflection makes this plugin compatible with multiple versions, but is really complicated

			// reflection code for this:
			// PacketPlayInClientCommand respawnPacket = new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN);

			Class<?> enumClazz = Class.forName(ReflectionUtil.getNMSPath()+"PacketPlayInClientCommand$EnumClientCommand");
			Object enumValue = enumClazz.getField("PERFORM_RESPAWN").get(null);

			Class<?> packetClazz = Class.forName(ReflectionUtil.getNMSPath()+"PacketPlayInClientCommand");
			Constructor<?> packetConstructor = packetClazz.getConstructor(enumClazz);
			Object packet = packetConstructor.newInstance(enumValue);

			// reflection code for this:
			// ((CraftPlayer) player).getHandle().playerConnection.a(respawnPacket);

			Class<?> craftPlayerClazz = Class.forName(ReflectionUtil.getCBPath()+"entity.CraftPlayer");
			Method getHandle = craftPlayerClazz.getMethod("getHandle");
			Object entityPlayer = getHandle.invoke(player);

			Class<?> entityPlayerClazz = Class.forName(ReflectionUtil.getNMSPath()+"EntityPlayer");
			Field entityPlayerPlayerConnectionField = entityPlayerClazz.getField("playerConnection");

			Object playerConnection = entityPlayerPlayerConnectionField.get(entityPlayer);

			Class<?> playerConnectionClass = Class.forName(ReflectionUtil.getNMSPath()+"PlayerConnection");
			Method a = playerConnectionClass.getMethod("a", packetClazz);
			a.invoke(playerConnection, packet);
		}
		catch(ClassNotFoundException|NoSuchMethodException|SecurityException|NoSuchFieldException|IllegalArgumentException|IllegalAccessException|InstantiationException|InvocationTargetException reflectionException)
		{
			reflectionException.printStackTrace();
		}
	}

	public static void heal(Player player, double health)
	{
		if(health <= 0)
			return;

		Damageable da = player;

		if((da.getHealth()+health) < da.getMaxHealth())
			player.setHealth(da.getHealth()+health);
		else
			player.setHealth(da.getMaxHealth());
	}

}<commit_msg>Added damage attribution helper method<commit_after>package de.domisum.auxiliumapi.util.bukkit;

import de.domisum.auxiliumapi.util.java.ReflectionUtil;
import net.minecraft.server.v1_9_R1.EntityLiving;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class PlayerUtil
{

	// MANIPULATION
	public static void clear(Player player)
	{
		player.getInventory().clear();
		player.getInventory().setArmorContents(null);

		player.setLevel(0);
		player.setExp(0);

		player.setHealth(player.getMaxHealth());
		player.setSaturation(5);
		player.setFoodLevel(20);

		for(PotionEffect pe : player.getActivePotionEffects())
			player.removePotionEffect(pe.getType());

		removeArrows(player);
	}

	public static void removeArrows(Player player)
	{
		// reflection makes this plugin compatible with multiple versions

		try
		{
			// reflection code for this:
			// ((CraftPlayer) player).getHandle().k(0);

			Class<?> craftPlayerClazz = Class.forName(ReflectionUtil.getCBPath()+"entity.CraftPlayer");
			Method getHandle = craftPlayerClazz.getMethod("getHandle");
			Object entityPlayer = getHandle.invoke(player);

			Method setArrows = entityPlayer.getClass().getMethod("k", int.class);
			setArrows.invoke(entityPlayer, 0);
		}
		catch(ClassNotFoundException|NoSuchMethodException|SecurityException|IllegalArgumentException|IllegalAccessException|InvocationTargetException reflectionException)
		{
			reflectionException.printStackTrace();
		}
	}

	public static void respawn(Player player)
	{
		try
		{
			// reflection makes this plugin compatible with multiple versions, but is really complicated

			// reflection code for this:
			// PacketPlayInClientCommand respawnPacket = new PacketPlayInClientCommand(EnumClientCommand.PERFORM_RESPAWN);

			Class<?> enumClazz = Class.forName(ReflectionUtil.getNMSPath()+"PacketPlayInClientCommand$EnumClientCommand");
			Object enumValue = enumClazz.getField("PERFORM_RESPAWN").get(null);

			Class<?> packetClazz = Class.forName(ReflectionUtil.getNMSPath()+"PacketPlayInClientCommand");
			Constructor<?> packetConstructor = packetClazz.getConstructor(enumClazz);
			Object packet = packetConstructor.newInstance(enumValue);

			// reflection code for this:
			// ((CraftPlayer) player).getHandle().playerConnection.a(respawnPacket);

			Class<?> craftPlayerClazz = Class.forName(ReflectionUtil.getCBPath()+"entity.CraftPlayer");
			Method getHandle = craftPlayerClazz.getMethod("getHandle");
			Object entityPlayer = getHandle.invoke(player);

			Class<?> entityPlayerClazz = Class.forName(ReflectionUtil.getNMSPath()+"EntityPlayer");
			Field entityPlayerPlayerConnectionField = entityPlayerClazz.getField("playerConnection");

			Object playerConnection = entityPlayerPlayerConnectionField.get(entityPlayer);

			Class<?> playerConnectionClass = Class.forName(ReflectionUtil.getNMSPath()+"PlayerConnection");
			Method a = playerConnectionClass.getMethod("a", packetClazz);
			a.invoke(playerConnection, packet);
		}
		catch(ClassNotFoundException|NoSuchMethodException|SecurityException|NoSuchFieldException|IllegalArgumentException|IllegalAccessException|InstantiationException|InvocationTargetException reflectionException)
		{
			reflectionException.printStackTrace();
		}
	}

	public static void heal(Player player, double health)
	{
		if(health <= 0)
			return;

		Damageable da = player;

		if((da.getHealth()+health) < da.getMaxHealth())
			player.setHealth(da.getHealth()+health);
		else
			player.setHealth(da.getMaxHealth());
	}

	// DAMAGING
	public static void causeDamage(Player player, EntityLiving target, double damage)
	{
		causeDamage(player, (LivingEntity) target.getBukkitEntity(), damage);
	}

	public static void causeDamage(Player player, LivingEntity target, double damage)
	{
		// unsure if this works
		target.damage(damage, player);
	}

}
{'fraction_non_alphanumeric': 0.11062061802129317, 'fraction_numerical': 0.002466891716437289, 'mean_word_length': 6.041133455210238, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5395604', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2199, 'n_words': 381}