package com.elmakers.mine.bukkit.plugins.magic.spells;

import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import com.elmakers.mine.bukkit.plugins.magic.Spell;
import com.elmakers.mine.bukkit.plugins.magic.SpellResult;
import com.elmakers.mine.bukkit.plugins.magic.Target;
import com.elmakers.mine.bukkit.utilities.URLMapRenderer;
import com.elmakers.mine.bukkit.utilities.borrowed.ConfigurationNode;

public class CameraSpell extends Spell
{
	@Override
	public SpellResult onCast(ConfigurationNode parameters) 
	{
		// Check for special case url
		ItemStack newMapItem = null;
		String url = parameters.getString("url");
		if (url != null) {
			int x = parameters.getInt("x", 0);
			int y = parameters.getInt("y", 0);
			int width = parameters.getInt("width", 0);
			int height = parameters.getInt("height", 0);
			newMapItem = URLMapRenderer.getURLItem(url, x, y, width, height, "Photo");
		}
		
		if (newMapItem == null) {
			this.targetEntity(Player.class);
			Target target = getTarget();
			String playerName = parameters.getString("name");
			if (playerName == null) 
			{
				Player targetPlayer = player;
				if (target != null && target.isEntity() && (target.getEntity() instanceof Player))
				{
					castMessage("CLICK!");
					targetPlayer = (Player)target.getEntity();
				} 
				else 
				{
					castMessage("Selfie!");
				}
				playerName = targetPlayer.getName();
			}
			if (parameters.containsKey("reload")) {
				URLMapRenderer.forceReloadPlayerPortrait(playerName);
			}
			newMapItem = URLMapRenderer.getPlayerPortrait(playerName);
		}
		if (newMapItem == null) {
			sendMessage("Failed to load photo");
			return SpellResult.FAILURE;
		}
		player.getWorld().dropItemNaturally(player.getLocation(), newMapItem);
		
		// Kinda hacky, but safe.
		URLMapRenderer.save();
		return SpellResult.SUCCESS;
	}
}

@@ -49,16 +49,70 @@
 pells;%0A%0A
+import org.bukkit.Effect;%0Aimport org.bukkit.Material;%0A
 import o
@@ -590,50 +590,239 @@
 %7B%0A%09%09
-// Check for special case url%0A%09%09ItemStack 
+ItemStack newMapItem = null;%0A%09%09%0A%09%09// Check for special case id%0A%09%09if (parameters.containsKey(%22id%22))%0A%09%09%7B%0A%09%09%09newMapItem = new ItemStack(Material.MAP, 1, (short)parameters.getInt(%22id%22, 0));%0A%09%09%7D%0A%09%09%0A%09%09// Check for special case url%0A%09%09if (
 newM
@@ -829,23 +829,27 @@
 apItem =
+=
  null
-;%0A
+) %7B%0A%09
 %09%09String
@@ -886,16 +886,17 @@
 rl%22);%0A%09%09
+%09
 if (url 
@@ -906,16 +906,17 @@
 null) %7B%0A
+%09
 %09%09%09int x
@@ -944,24 +944,25 @@
 %22x%22, 0);%0A%09%09%09
+%09
 int y = para
@@ -980,24 +980,25 @@
 nt(%22y%22, 0);%0A
+%09
 %09%09%09int width
@@ -1031,16 +1031,17 @@
 h%22, 0);%0A
+%09
 %09%09%09int h
@@ -1079,24 +1079,25 @@
 ht%22, 0);%0A%09%09%09
+%09
 newMapItem =
@@ -1159,16 +1159,21 @@
 hoto%22);%0A
+%09%09%09%7D%0A
 %09%09%7D%0A%09%09%0A%09
@@ -2008,16 +2008,90 @@
 pItem);%0A
+%09%09player.getWorld().playEffect(player.getEyeLocation(), Effect.SMOKE, 0);%0A
 %09%09%0A%09%09// 

Allow getting a url map by id