package com.github.niwaniwa.we.core.command.twitter;

import org.bukkit.command.Command;
import org.bukkit.scheduler.BukkitRunnable;

import com.github.niwaniwa.we.core.WhiteEggCore;
import com.github.niwaniwa.we.core.command.abstracts.AbstractWhiteEggCoreCommand;
import com.github.niwaniwa.we.core.command.abstracts.ConsoleCancellable;
import com.github.niwaniwa.we.core.player.WhiteCommandSender;
import com.github.niwaniwa.we.core.player.WhitePlayer;
import com.github.niwaniwa.we.core.twitter.PlayerTwitterManager;
import com.github.niwaniwa.we.core.util.message.LanguageType;

public class WhiteEggTwitterCommand extends AbstractWhiteEggCoreCommand implements ConsoleCancellable {

	private final String key = commandMessageKey + ".twitter";
	private final String permission = commandPermission + ".twitter";

	@Override
	public boolean onCommand(WhiteCommandSender sender, Command cmd, String label, String[] args) {
		if(!sender.hasPermission(permission)){
			sender.sendMessage(msg.getMessage(sender, error_Permission, "", true));
			return true;
		}

		final WhitePlayer player = (WhitePlayer) sender;

		if(args.length == 0){
			this.sendUsing(player);
			return true;
		}

		if(player.getTwitterManager().getAccessToken() == null){
			player.sendMessage(
					msg.getMessage(player, key + ".notAcccess", msgPrefix, true));
			return true;
		}

		StringBuilder sb = new StringBuilder();
		for(String str : args){
			sb.append(str).append(" ");
		}
		// tweet
		player.getTwitterManager().tweet(sb.toString());

		new BukkitRunnable() {
			@Override
			public void run() {
				if((player.getTwitterManager()).isSuccessfull()){
					player.sendMessage(msg.getMessage(player, key + ".successfull", msgPrefix, true));
					return;
				}
				player.sendMessage(msg.getMessage(player, key + ".failure", msgPrefix, true));
			}
		}.runTaskLater(WhiteEggCore.getInstance(), 2 * 20);

		((PlayerTwitterManager) player.getTwitterManager()).set(false);
		return true;
	}

	@Override
	public void sendUsing(WhitePlayer sender) {
		sender.sendMessage("&7----- &6/twitter &7-----");
		sender.sendMessage("");
	}

	@Override
	public String getPermission() {
		return permission;
	}

	@Override
	public String description() {
		return msg.getMessage(LanguageType.en_US, key + ".description", "", true);
	}

	@Override
	public String description(WhiteCommandSender sender) {
		return msg.getMessage(sender, key + ".description", "", true);
	}

}

@@ -85,52 +85,8 @@
 and;
-%0Aimport org.bukkit.scheduler.BukkitRunnable;
 %0A%0Aim
@@ -118,28 +118,28 @@
 we.core.
-WhiteEggCore
+api.Callback
 ;%0Aimport
@@ -408,73 +408,8 @@
 er;%0A
-import com.github.niwaniwa.we.core.twitter.PlayerTwitterManager;%0A
 impo
@@ -944,17 +944,16 @@
 ue;%0A%09%09%7D%0A
-%0A
 %09%09final 
@@ -995,17 +995,16 @@
 sender;%0A
-%0A
 %09%09if(arg
@@ -1404,32 +1404,22 @@
 ng()
-);%0A%0A%09%09new BukkitRunnable
+, new Callback
 () %7B
@@ -1451,66 +1451,75 @@
 oid 
-run() %7B%0A%09%09%09%09if((player.getTwitterManager()).isSuccessfull(
+call(Object... obj) %7B%0A%09%09%09%09if(Boolean.valueOf(String.valueOf(obj%5B0%5D)
 ))%7B%0A
@@ -1720,123 +1720,8 @@
 %0A%09%09%7D
-.runTaskLater(WhiteEggCore.getInstance(), 2 * 20);%0A%0A%09%09((PlayerTwitterManager) player.getTwitterManager()).set(false
 );%0A%09
@@ -1868,16 +1868,46 @@
 essage(%22
+&7/twitter %3Ctweet%3E &f: %E3%83%84%E3%82%A4%E3%83%BC%E3%83%88%E3%81%97%E3%81%BE%E3%81%99
 %22);%0A%09%7D%0A%0A

Change TwitterCommand