<commit_before>package protocolsupport.api.chat.modifiers;

import java.util.UUID;

import org.bukkit.Achievement;
import org.bukkit.Statistic;
import org.bukkit.craftbukkit.v1_8_R3.CraftStatistic;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;

import net.minecraft.server.v1_8_R3.MojangsonParseException;
import net.minecraft.server.v1_8_R3.MojangsonParser;
import net.minecraft.server.v1_8_R3.NBTTagCompound;

import protocolsupport.api.chat.ChatAPI;
import protocolsupport.api.chat.components.BaseComponent;
import protocolsupport.api.utils.Any;

public class HoverAction {

	private Type type;
	private String value;

	public HoverAction(Type type, String value) {
		this.type = type;
		this.value = value;
	}

	public HoverAction(BaseComponent component) {
		this.type = Type.SHOW_TEXT;
		this.value = ChatAPI.toJSON(component);
	}

	public HoverAction(ItemStack itemstack) {
		this.type = Type.SHOW_ITEM;
		net.minecraft.server.v1_8_R3.ItemStack nmsitemstack = CraftItemStack.asNMSCopy(itemstack);
		NBTTagCompound compound = new NBTTagCompound();
		nmsitemstack.save(compound);
		this.value = compound.toString();
	}

	public HoverAction(Entity entity) {
		this(new EntityInfo(entity));
	}

	@SuppressWarnings("deprecation")
	public HoverAction(EntityInfo entityinfo) {
		this.type = Type.SHOW_ENTITY;
		NBTTagCompound compound = new NBTTagCompound();
		compound.setString("type", entityinfo.getType().getName());
		compound.setString("id", entityinfo.getUUID().toString());
		compound.setString("name", entityinfo.getName());
		this.value = compound.toString();
	}

	public HoverAction(Achievement achievment) {
		this.type = Type.SHOW_ACHIEVEMENT;
		this.value = CraftStatistic.getNMSAchievement(achievment).name;
	}

	public HoverAction(Statistic stat) {
		this.type = Type.SHOW_ACHIEVEMENT;
		this.value = CraftStatistic.getNMSStatistic(stat).name;
	}

	public Type getType() {
		return type;
	}

	public String getValue() {
		return value;
	}

	public BaseComponent getText() {
		validateAction(type, Type.SHOW_TEXT);
		return ChatAPI.fromJSON(value);
	}

	public ItemStack getItemStack() {
		validateAction(type, Type.SHOW_ITEM);
		try {
			return CraftItemStack.asCraftMirror(net.minecraft.server.v1_8_R3.ItemStack.createStack(MojangsonParser.parse(getValue())));
		} catch (MojangsonParseException e) {
			throw new IllegalStateException("Unable to parse value to itemstack");
		}
	}

	@SuppressWarnings("deprecation")
	public EntityInfo getEntity() {
		validateAction(type, Type.SHOW_ENTITY);
		try {
			NBTTagCompound compound = MojangsonParser.parse(getValue());
			return new EntityInfo(EntityType.fromName(compound.getString("type")), UUID.fromString(compound.getString("id")), compound.getString("name"));
		} catch (MojangsonParseException e) {
			throw new IllegalStateException("Unable to parse value to entity info");
		}
	}

	public Any<Achievement, Statistic> getAchievmentOrStat() {
		validateAction(type, Type.SHOW_ACHIEVEMENT);
		Achievement achievement = CraftStatistic.getBukkitAchievementByName(getValue());
		Statistic stat = CraftStatistic.getBukkitStatisticByName(getValue());
		return new Any<>(achievement, stat);
	}

	static void validateAction(Type current, Type expected) {
		if (current != expected) {
			throw new IllegalStateException(current + " is not an "+expected);
		}
	}

	public static enum Type {
		SHOW_TEXT, SHOW_ACHIEVEMENT, SHOW_ITEM, SHOW_ENTITY;
	}

	public static class EntityInfo {
		private EntityType etype;
		private UUID uuid;
		private String name;

		public EntityInfo(EntityType etype, UUID uuid, String name) {
			this.etype = etype;
			this.uuid = uuid;
			this.name = name;
		}

		public EntityInfo(Entity entity) {
			this(entity.getType(), entity.getUniqueId(), entity.getName());<commit_msg>Should use field, not method.<commit_after>package protocolsupport.api.chat.modifiers;

import java.util.UUID;

import org.bukkit.Achievement;
import org.bukkit.Statistic;
import org.bukkit.craftbukkit.v1_8_R3.CraftStatistic;
import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;

import net.minecraft.server.v1_8_R3.MojangsonParseException;
import net.minecraft.server.v1_8_R3.MojangsonParser;
import net.minecraft.server.v1_8_R3.NBTTagCompound;

import protocolsupport.api.chat.ChatAPI;
import protocolsupport.api.chat.components.BaseComponent;
import protocolsupport.api.utils.Any;

public class HoverAction {

	private Type type;
	private String value;

	public HoverAction(Type type, String value) {
		this.type = type;
		this.value = value;
	}

	public HoverAction(BaseComponent component) {
		this.type = Type.SHOW_TEXT;
		this.value = ChatAPI.toJSON(component);
	}

	public HoverAction(ItemStack itemstack) {
		this.type = Type.SHOW_ITEM;
		net.minecraft.server.v1_8_R3.ItemStack nmsitemstack = CraftItemStack.asNMSCopy(itemstack);
		NBTTagCompound compound = new NBTTagCompound();
		nmsitemstack.save(compound);
		this.value = compound.toString();
	}

	public HoverAction(Entity entity) {
		this(new EntityInfo(entity));
	}

	@SuppressWarnings("deprecation")
	public HoverAction(EntityInfo entityinfo) {
		this.type = Type.SHOW_ENTITY;
		NBTTagCompound compound = new NBTTagCompound();
		compound.setString("type", entityinfo.getType().getName());
		compound.setString("id", entityinfo.getUUID().toString());
		compound.setString("name", entityinfo.getName());
		this.value = compound.toString();
	}

	public HoverAction(Achievement achievment) {
		this.type = Type.SHOW_ACHIEVEMENT;
		this.value = CraftStatistic.getNMSAchievement(achievment).name;
	}

	public HoverAction(Statistic stat) {
		this.type = Type.SHOW_ACHIEVEMENT;
		this.value = CraftStatistic.getNMSStatistic(stat).name;
	}

	public Type getType() {
		return type;
	}

	public String getValue() {
		return value;
	}

	public BaseComponent getText() {
		validateAction(type, Type.SHOW_TEXT);
		return ChatAPI.fromJSON(value);
	}

	public ItemStack getItemStack() {
		validateAction(type, Type.SHOW_ITEM);
		try {
			return CraftItemStack.asCraftMirror(net.minecraft.server.v1_8_R3.ItemStack.createStack(MojangsonParser.parse(value)));
		} catch (MojangsonParseException e) {
			throw new IllegalStateException("Unable to parse value to itemstack");
		}
	}

	@SuppressWarnings("deprecation")
	public EntityInfo getEntity() {
		validateAction(type, Type.SHOW_ENTITY);
		try {
			NBTTagCompound compound = MojangsonParser.parse(value);
			return new EntityInfo(EntityType.fromName(compound.getString("type")), UUID.fromString(compound.getString("id")), compound.getString("name"));
		} catch (MojangsonParseException e) {
			throw new IllegalStateException("Unable to parse value to entity info");
		}
	}

	public Any<Achievement, Statistic> getAchievmentOrStat() {
		validateAction(type, Type.SHOW_ACHIEVEMENT);
		Achievement achievement = CraftStatistic.getBukkitAchievementByName(value);
		Statistic stat = CraftStatistic.getBukkitStatisticByName(value);
		return new Any<>(achievement, stat);
	}

	static void validateAction(Type current, Type expected) {
		if (current != expected) {
			throw new IllegalStateException(current + " is not an "+expected);
		}
	}

	public static enum Type {
		SHOW_TEXT, SHOW_ACHIEVEMENT, SHOW_ITEM, SHOW_ENTITY;
	}

	public static class EntityInfo {
		private EntityType etype;
		private UUID uuid;
		private String name;

		public EntityInfo(EntityType etype, UUID uuid, String name) {
			this.etype = etype;
			this.uuid = uuid;
			this.name = name;
		}

		public EntityInfo(Entity entity) {
			this(entity.getType(), entity.getUniqueId(), entity.getName());
{'fraction_non_alphanumeric': 0.11056826947801492, 'fraction_numerical': 0.0053998457186937516, 'mean_word_length': 5.428925619834711, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3015632', 'n_tokens_mistral': 2753, 'n_tokens_neox': 2608, 'n_words': 487}