package com.github.niwaniwa.we.core.util.lib.clickable;

import java.util.List;

import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;

import com.github.niwaniwa.we.core.util.Extension;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
import net.minecraft.server.v1_8_R3.PacketPlayOutChat;

public class Clickable extends Extension {

	private JsonObject json;

	/**
	 * Constructor
	 * @param text 表示する文字列
	 * @param color 文字列の装飾
	 * @param formats フォーマット
	 */
	public Clickable(String text, ChatColor color, List<ChatFormat> formats) {
		json = new JsonObject();
		json.addProperty("text", text);
		if (color != null) {
			json.addProperty("color", color.toString().toLowerCase());
		}
		if (formats != null) { formats.forEach(f -> json.addProperty(f.getFormat(), true)); }
	}

	/**
	 * Eventなどを追加します
	 * @param extraInstance ChatExtra
	 */
	public void addExtra(ChatExtra extraInstance) {
		if (json.get("extra") == null) { return; }
		JsonArray extra = json.getAsJsonArray("extra");
		extra.add(extraInstance.toJson());
		json.add("extra", extra);
	}

	@Override
	public void send(Player player) {
		((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(ChatSerializer.a(json.toString())));
	}

}

@@ -1048,53 +1048,8 @@
 ) %7B%0A
-%09%09if (json.get(%22extra%22) == null) %7B return; %7D%0A
 %09%09Js
@@ -1068,18 +1068,12 @@
 a = 
-json.getAs
+new 
 Json
@@ -1078,23 +1078,16 @@
 onArray(
-%22extra%22
 );%0A%09%09ext

Fix clickable