This commit is contained in:
Coutume 2014-01-29 18:05:06 +01:00
parent 939b01f995
commit 2828445706
4 changed files with 68 additions and 2 deletions

View File

@ -3,11 +3,14 @@ package fr.moribus.ImageOnMap;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
public final class ImageOnMap extends JavaPlugin
@ -17,6 +20,9 @@ public final class ImageOnMap extends JavaPlugin
boolean dossierCree;
private FileConfiguration customConfig = null;
private File customConfigFile = null;
// liste contenant les maps ne pouvant être placé dans l'inventaire du joueur. Je le fous ici afin que ce soit
// accessible de partout dans le plugin..
private HashMap<String, ArrayList<ItemStack>> cache = new HashMap<String, ArrayList<ItemStack>>();
@Override
public void onEnable()
@ -126,5 +132,20 @@ public final class ImageOnMap extends JavaPlugin
getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
}
}
public ArrayList<ItemStack> getRemainingMaps(String j)
{
return cache.get(j);
}
public void setRemainingMaps(String j, ArrayList<ItemStack> remaining)
{
cache.put(j, remaining);
}
public void removeRemaingMaps(String j)
{
cache.remove(j);
}
}

View File

@ -2,6 +2,7 @@ package fr.moribus.ImageOnMap;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import org.bukkit.Bukkit;
@ -10,6 +11,8 @@ import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.map.MapView;
public class ImgUtility
@ -228,4 +231,14 @@ public class ImgUtility
}
return listeMap;
}
static void AddMap(ItemStack map, Inventory inv, ArrayList<ItemStack> restant)
{
HashMap<Integer,ItemStack> reste = inv.addItem(map);
if(!reste.isEmpty())
{
restant.add(reste.get(0));
}
}
}

View File

@ -130,6 +130,31 @@ public class MapToolCommand implements CommandExecutor
"\nYou have rendered "+ ChatColor.DARK_PURPLE+ (compteur + 1)+ ChatColor.RESET+ " pictures");
}
else if(arg3[0].equalsIgnoreCase("getrest"))
{
if(plugin.getRemainingMaps(joueur.getName()) == null)
{
joueur.sendMessage("All maps have already be placed in your inventory");
return true;
}
ArrayList<ItemStack> reste = plugin.getRemainingMaps(joueur.getName());
ArrayList<ItemStack> restant = new ArrayList<ItemStack>();
for(int i = 0; i < reste.size(); i++)
{
ImgUtility.AddMap(reste.get(i), inv, restant);
}
if(restant.isEmpty())
{
plugin.removeRemaingMaps(joueur.getName());
joueur.sendMessage("All maps have been placed in your inventory");
}
else
{
plugin.setRemainingMaps(joueur.getName(), restant);
joueur.sendMessage(restant.size()+ " maps can't be placed in your inventory. Please run "+ ChatColor.GOLD+ "/maptool getrest again");
}
}
return true;
}

View File

@ -1,5 +1,7 @@
package fr.moribus.ImageOnMap;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -59,6 +61,7 @@ public class TacheTraitementMap extends BukkitRunnable
}
MapView carte;
ArrayList<ItemStack> restant = new ArrayList<ItemStack>();
for (int i = 0; i < nbImage; i++)
{
carte = Bukkit.createMap(joueur.getWorld());
@ -68,14 +71,18 @@ public class TacheTraitementMap extends BukkitRunnable
ItemMeta meta = map.getItemMeta();
meta.setDisplayName("Map (" +renduImg.getImg().NumeroMap.get(i) +")");
map.setItemMeta(meta);
inv.addItem(map);
ImgUtility.AddMap(map, inv, restant);
//Svg de la map
SavedMap svg = new SavedMap(plugin, joueur.getName(), carte.getId(), renduImg.getImg().getPoster()[i]);
svg.SaveMap();
joueur.sendMap(carte);
}
joueur.sendMessage("Rendu de l'image fini");
if(!restant.isEmpty())
joueur.sendMessage(restant.size()+ " maps can't be place in your inventory. Please make free space in your inventory and run "+ ChatColor.GOLD+ "/maptool rest");
plugin.setRemainingMaps(joueur.getName(), restant);
joueur.sendMessage("Render finished");
}
}