mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-01-09 01:07:50 +01:00
Préversion 4. Voir commit suivant (encore ) pour les détails
This commit is contained in:
parent
6b9e5ef5e0
commit
b1a7734f86
139
src/fr/moribus/ImageOnMap/DownloadImageThread.java
Normal file
139
src/fr/moribus/ImageOnMap/DownloadImageThread.java
Normal file
@ -0,0 +1,139 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
|
||||
public class DownloadImageThread implements Callable<BufferedImage>
|
||||
{
|
||||
private String stringUrl;
|
||||
private BufferedImage imgSrc;
|
||||
/*private BufferedImage[] img;
|
||||
private Poster poster;
|
||||
private boolean resized;*/
|
||||
|
||||
DownloadImageThread(String u/*, boolean r*/)
|
||||
{
|
||||
stringUrl = u;
|
||||
//resized = r;
|
||||
}
|
||||
|
||||
/*public BufferedImage[] getImg()
|
||||
{
|
||||
if (!this.isAlive())
|
||||
return img;
|
||||
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public HashMap<Integer, String> getNumeroMap()
|
||||
{
|
||||
return poster.NumeroMap;
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
URI uri = null;
|
||||
java.net.URL url = null;
|
||||
try
|
||||
{
|
||||
uri = URI.create(URL);
|
||||
url = uri.toURL();
|
||||
|
||||
|
||||
}
|
||||
catch (IllegalArgumentException | MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
erreur = true;
|
||||
return;
|
||||
}
|
||||
if(erreur != true)
|
||||
{
|
||||
try {
|
||||
imgSrc = ImageIO.read(url.openStream());
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
//
|
||||
erreur = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(resized)
|
||||
{
|
||||
img = new BufferedImage[1];
|
||||
Image i = imgSrc.getScaledInstance(128, 128, Image.SCALE_SMOOTH);
|
||||
BufferedImage imgScaled = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
|
||||
imgScaled.getGraphics().drawImage(i, 0, 0 , null);
|
||||
img[0] = imgScaled;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int width = imgSrc.getWidth();
|
||||
int height = imgSrc.getHeight();
|
||||
|
||||
// Fonction qui cherche le multiple de 128 le plus proche
|
||||
// de la hauteur / largeur de l'image
|
||||
int tmpW = 0, tmpH = 0;
|
||||
int i = 1;
|
||||
while (tmpW < width)
|
||||
{
|
||||
|
||||
tmpW = i * 128;
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (tmpH < height)
|
||||
{
|
||||
|
||||
tmpH = i * 128;
|
||||
i++;
|
||||
}
|
||||
|
||||
// On crée un "canvas" = une image vide qui a une taille multiple de 128
|
||||
// dans laquelle on dessinera l'image téléchargées
|
||||
BufferedImage canvas = new BufferedImage(tmpW, tmpH, BufferedImage.TYPE_INT_ARGB);
|
||||
// On récupère l'objet Grapics2D, servant à dessiner dans notre canvas
|
||||
Graphics2D graph = canvas.createGraphics();
|
||||
|
||||
// Variable servant à cadrer l'image
|
||||
int centerX = 0, centerY = 0;
|
||||
centerX = (tmpW - imgSrc.getWidth()) / 2;
|
||||
centerY = (tmpH - imgSrc.getHeight()) / 2;
|
||||
//On déplace le point d'origine de graph afin que l'image soit dessinée au milieu du canvas
|
||||
graph.translate(centerX, centerY);
|
||||
//graph.rotate(45);
|
||||
// on dessine l'image dans le canvas
|
||||
graph.drawImage(imgSrc, null, null);
|
||||
// on crée un Poster à partir de notre canvas
|
||||
poster = new Poster(canvas);
|
||||
img = poster.getPoster();
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public BufferedImage call() throws Exception
|
||||
{
|
||||
URL url = new URL(stringUrl);
|
||||
|
||||
try
|
||||
{
|
||||
imgSrc = ImageIO.read(url.openStream());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
imgSrc = null;
|
||||
}
|
||||
return imgSrc;
|
||||
}
|
||||
|
||||
}
|
@ -10,42 +10,34 @@ import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
|
||||
import fr.moribus.ImageOnMap.Map.ImageMap;
|
||||
import fr.moribus.ImageOnMap.Map.SingleMap;
|
||||
|
||||
public final class ImageOnMap extends JavaPlugin
|
||||
{
|
||||
int test = 0;
|
||||
File dossier;
|
||||
private 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.. */
|
||||
accessible de partout dans le plugin. */
|
||||
private HashMap<String, ArrayList<ItemStack>> cache = new HashMap<String, ArrayList<ItemStack>>();
|
||||
|
||||
// Index des maps chargées sur le serveur
|
||||
public ArrayList<Short> mapChargee = new ArrayList<Short>();
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
/*MapASuppr = (ArrayList<String>) getConfig().getStringList("delete");
|
||||
if(getConfig().get("map_path") != null && !MapASuppr.isEmpty())
|
||||
{
|
||||
for(int i = 0; i < MapASuppr.size(); i++)
|
||||
{
|
||||
File map = new File(getDataFolder()+ "/../../"+ getConfig().getString("map_path")+ "/data/map_"+ MapASuppr.get(i)+ ".dat");
|
||||
boolean deleted = map.delete();
|
||||
if(!deleted)
|
||||
getLogger().info("Could not delete map_"+ MapASuppr.get(i)+ ".dat on world folder " +getConfig().getString("map_path"));
|
||||
}
|
||||
getConfig().set("delete", null);
|
||||
saveConfig();
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
@ -62,7 +54,6 @@ public final class ImageOnMap extends JavaPlugin
|
||||
if(getConfig().getBoolean("import-maps"))
|
||||
ImgUtility.ImporterConfig(this);
|
||||
|
||||
ChargerMap();
|
||||
if(this.getConfig().getBoolean("collect-data"))
|
||||
{
|
||||
try
|
||||
@ -82,7 +73,6 @@ public final class ImageOnMap extends JavaPlugin
|
||||
getCommand("maptool").setExecutor(new MapToolCommand(this));
|
||||
getServer().getPluginManager().registerEvents(new SendMapOnFrameEvent(this), this);
|
||||
getServer().getPluginManager().registerEvents(new SendMapOnInvEvent(this), this);
|
||||
//getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
|
||||
this.saveDefaultConfig();
|
||||
//ChargerMap();
|
||||
}
|
||||
@ -92,6 +82,18 @@ public final class ImageOnMap extends JavaPlugin
|
||||
this.setEnabled(false);
|
||||
}
|
||||
|
||||
// Disable all sound effects
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(
|
||||
new PacketAdapter(this, ListenerPriority.NORMAL,
|
||||
PacketType.Play.Server.SPAWN_ENTITY_LIVING)
|
||||
{
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event)
|
||||
{
|
||||
event.getPacket().getIntegers().write(1, (int) EntityType.BLAZE.getTypeId());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -108,12 +110,25 @@ public final class ImageOnMap extends JavaPlugin
|
||||
{
|
||||
if(getCustomConfig().getStringList(s).size() >= 3)
|
||||
{
|
||||
SavedMap map = new SavedMap(this, Short.valueOf(getCustomConfig().getStringList(s).get(0)));
|
||||
|
||||
if(map.LoadMap())
|
||||
nbMap++;
|
||||
else
|
||||
ImageMap map;
|
||||
try
|
||||
{
|
||||
map = new SingleMap(Short.valueOf(getCustomConfig().getStringList(s).get(0)));
|
||||
|
||||
if(map.load())
|
||||
nbMap++;
|
||||
else
|
||||
nbErr++;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
nbErr++;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
nbErr++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -124,9 +139,10 @@ public final class ImageOnMap extends JavaPlugin
|
||||
|
||||
/* Méthodes pour charger / recharger / sauvegarder
|
||||
* le fichier conf des maps (map.yml).
|
||||
* Je les ai juste copié depuis un tuto du wiki Bukkit...
|
||||
* Je les ai juste copié depuis un tuto du wiki Bukkit.
|
||||
*/
|
||||
public void reloadCustomConfig()
|
||||
@SuppressWarnings("deprecation")
|
||||
public void reloadCustomConfig()
|
||||
{
|
||||
if (customConfigFile == null)
|
||||
{
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class ImageRenduCommande implements CommandExecutor
|
||||
{
|
||||
|
||||
Player joueur;
|
||||
boolean renderName, imgSvg;
|
||||
ImageOnMap plugin;
|
||||
@ -19,7 +18,7 @@ public class ImageRenduCommande implements CommandExecutor
|
||||
{
|
||||
plugin = p;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command arg1, String arg2,
|
||||
String[] arg3)
|
||||
@ -59,14 +58,6 @@ public class ImageRenduCommande implements CommandExecutor
|
||||
return true;
|
||||
}
|
||||
|
||||
/*if(arg3.length == 1 && arg3[0].equalsIgnoreCase("test"))
|
||||
{
|
||||
MapView map = Bukkit.createMap(joueur.getWorld());
|
||||
TacheHorloge tache = new TacheHorloge(joueur, map);
|
||||
tache.runTaskTimer(plugin, 0, 150);
|
||||
return true;
|
||||
}*/
|
||||
|
||||
if(arg3.length >= 2)
|
||||
{
|
||||
for(int i = 1; i < arg3.length; i++)
|
||||
@ -79,8 +70,8 @@ public class ImageRenduCommande implements CommandExecutor
|
||||
}
|
||||
|
||||
|
||||
TacheTraitementMap tache = new TacheTraitementMap(joueur, arg3[0], plugin, resize, rename);
|
||||
tache.runTaskTimer(plugin, 0, 10);
|
||||
TacheTraitementMap tache = new TacheTraitementNouvelleMap(joueur, arg3[0], resize, rename);
|
||||
tache.runTaskTimer(plugin, 0, 5);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
import fr.moribus.ImageOnMap.Map.SingleMap;
|
||||
|
||||
public class ImgUtility
|
||||
{
|
||||
|
||||
@ -196,7 +198,7 @@ public class ImgUtility
|
||||
else if(id == Short.parseShort(plugin.getCustomConfig().getStringList(s).get(0)))
|
||||
{
|
||||
//joueur.sendMessage("Suppression de la map dans fichier conf + fichier dat");
|
||||
ImageRendererThread.SupprRendu(carte);
|
||||
SingleMap.SupprRendu(carte);
|
||||
/*if(plugin.getConfig().get("delete") != null);
|
||||
{
|
||||
ArrayList<String> ListeSuppr = (ArrayList<String>) plugin.getConfig().getStringList("delete");
|
||||
|
73
src/fr/moribus/ImageOnMap/Map/AnimatedMap.java
Normal file
73
src/fr/moribus/ImageOnMap/Map/AnimatedMap.java
Normal file
@ -0,0 +1,73 @@
|
||||
package fr.moribus.ImageOnMap.Map;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AnimatedMap implements ImageObserver
|
||||
{
|
||||
private ImageMap map;
|
||||
private ImageIcon icon;
|
||||
private BufferedImage img;
|
||||
private Player joueur;
|
||||
|
||||
public AnimatedMap(ImageMap map, Player j) throws MalformedURLException
|
||||
{
|
||||
this.map = map;
|
||||
icon = new ImageIcon(new URL("http://upload.wikimedia.org/wikipedia/commons/5/55/Tesseract.gif"));
|
||||
img = new BufferedImage(256, 256, BufferedImage.TYPE_4BYTE_ABGR);
|
||||
joueur = j;
|
||||
icon.setImageObserver(this);
|
||||
}
|
||||
|
||||
public void animer()
|
||||
{
|
||||
icon.paintIcon(null, img.getGraphics(), 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean imageUpdate(Image gif, int infoflags, int x, int y,
|
||||
int width, int height)
|
||||
{
|
||||
if ((infoflags & ImageObserver.FRAMEBITS) != 0)
|
||||
{
|
||||
Bukkit.getScheduler().runTask(Bukkit.getPluginManager().getPlugin("ImageOnMap"), new DessinerAnimation(gif));
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(300);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class DessinerAnimation implements Runnable
|
||||
{
|
||||
private Image image;
|
||||
public DessinerAnimation(Image image)
|
||||
{
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
img.getGraphics().clearRect(0, 0, 128, 128);
|
||||
img.getGraphics().drawImage(image, 0, 0, null);
|
||||
map.setImage(img);
|
||||
map.send(joueur);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
16
src/fr/moribus/ImageOnMap/Map/ImageMap.java
Normal file
16
src/fr/moribus/ImageOnMap/Map/ImageMap.java
Normal file
@ -0,0 +1,16 @@
|
||||
package fr.moribus.ImageOnMap.Map;
|
||||
|
||||
import java.awt.Image;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface ImageMap
|
||||
{
|
||||
public boolean load();
|
||||
public boolean save();
|
||||
public void give(Inventory inv);
|
||||
public boolean isNamed();
|
||||
public void setImage(Image image);
|
||||
public void send(Player joueur);
|
||||
}
|
109
src/fr/moribus/ImageOnMap/Map/MapData.java
Normal file
109
src/fr/moribus/ImageOnMap/Map/MapData.java
Normal file
@ -0,0 +1,109 @@
|
||||
package fr.moribus.ImageOnMap.Map;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import fr.moribus.ImageOnMap.ImageOnMap;
|
||||
|
||||
public class MapData
|
||||
{
|
||||
private short id;
|
||||
private String joueur;
|
||||
private String monde;
|
||||
private String nom;
|
||||
private Image image;
|
||||
|
||||
|
||||
public Image getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(Image image)
|
||||
{
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public MapData(short id, String joueur, Image image, String monde)
|
||||
{
|
||||
this.id = id;
|
||||
this.joueur = joueur;
|
||||
this.monde = monde;
|
||||
this.image = image;
|
||||
}
|
||||
|
||||
public MapData(short id, String joueur, Image image, String monde, String nom)
|
||||
{
|
||||
this.id = id;
|
||||
this.joueur = joueur;
|
||||
this.monde = monde;
|
||||
this.setNom(nom);
|
||||
}
|
||||
|
||||
public MapData(short id) throws Exception
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean save()
|
||||
{
|
||||
boolean ok = true;
|
||||
String nomImg = "map"+ id;
|
||||
ImageOnMap plugin = (ImageOnMap)Bukkit.getPluginManager().getPlugin("ImageOnMap");
|
||||
try
|
||||
{
|
||||
File outputfile = new File("./plugins/ImageOnMap/Image/"+ nomImg + ".png");
|
||||
ImageIO.write((BufferedImage)image, "png", outputfile);
|
||||
|
||||
// Enregistrement de la map dans la config
|
||||
ArrayList<String> liste = new ArrayList<String>();
|
||||
liste.add(String.valueOf(id));
|
||||
liste.add(nomImg);
|
||||
liste.add(joueur);
|
||||
liste.add(monde);
|
||||
plugin.getCustomConfig().set(nomImg, liste);
|
||||
plugin.saveCustomConfig();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
ok = false;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
public void load() throws IOException
|
||||
{
|
||||
ImageOnMap plugin = (ImageOnMap)Bukkit.getPluginManager().getPlugin("ImageOnMap");
|
||||
List<String> svg = plugin.getCustomConfig().getStringList("map"+id);
|
||||
String nomImg = svg.get(1);
|
||||
joueur = svg.get(2);
|
||||
try
|
||||
{
|
||||
image = ImageIO.read(new File("./plugins/ImageOnMap/Image/"+ nomImg + ".png"));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
plugin.getLogger().log(Level.WARNING, "Image "+ nomImg +".png doesn't exists in Image directory.");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
}
|
155
src/fr/moribus/ImageOnMap/Map/PosterData.java
Normal file
155
src/fr/moribus/ImageOnMap/Map/PosterData.java
Normal file
@ -0,0 +1,155 @@
|
||||
package fr.moribus.ImageOnMap.Map;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import fr.moribus.ImageOnMap.ImageOnMap;
|
||||
|
||||
public class PosterData
|
||||
{
|
||||
private String joueur;
|
||||
private short[] idMaps;
|
||||
private String nomPoster;
|
||||
|
||||
private FileConfiguration customConfig = null;
|
||||
private File customConfigFile = null;
|
||||
|
||||
public PosterData(String joueur, short[] ids)
|
||||
{
|
||||
setJoueur(joueur);
|
||||
setIdMaps(ids);
|
||||
nomPoster = "poster"+ increment();
|
||||
}
|
||||
|
||||
public PosterData(String id) throws Exception
|
||||
{
|
||||
load(id);
|
||||
}
|
||||
|
||||
public String getJoueur()
|
||||
{
|
||||
return joueur;
|
||||
}
|
||||
|
||||
private void setJoueur(String joueur)
|
||||
{
|
||||
this.joueur = joueur;
|
||||
}
|
||||
|
||||
public short[] getIdMaps()
|
||||
{
|
||||
return idMaps;
|
||||
}
|
||||
|
||||
private void setIdMaps(short[] idMaps)
|
||||
{
|
||||
this.idMaps = idMaps;
|
||||
}
|
||||
|
||||
private void load(String id) throws Exception
|
||||
{
|
||||
List<String> svg = getCustomConfig().getStringList(id);
|
||||
if(svg != null && !svg.isEmpty())
|
||||
{
|
||||
nomPoster = id;
|
||||
setJoueur(svg.get(0));
|
||||
|
||||
try
|
||||
{
|
||||
short[] ids = new short[svg.size()-1];
|
||||
for(int i = 0; i < ids.length; i++)
|
||||
{
|
||||
ids[i] = Short.parseShort(svg.get(i+1));
|
||||
}
|
||||
setIdMaps(ids);
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Le poster est introuvable.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
ArrayList<String> liste = new ArrayList<String>();
|
||||
liste.add(joueur);
|
||||
for(int i= 0; i< idMaps.length; i++)
|
||||
{
|
||||
liste.add(String.valueOf(idMaps[i]));
|
||||
}
|
||||
getCustomConfig().set(nomPoster, liste);
|
||||
saveCustomConfig();
|
||||
}
|
||||
|
||||
private int increment()
|
||||
{
|
||||
int i;
|
||||
if(getCustomConfig().get("IdCount") != null)
|
||||
i = getCustomConfig().getInt("IdCount");
|
||||
else
|
||||
i = 0;
|
||||
i++;
|
||||
this.getCustomConfig().set("IdCount", i);
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Méthodes pour charger / recharger / sauvegarder
|
||||
* le fichier conf des Posters (poster.yml).
|
||||
* Je les ai juste copié depuis un tuto du wiki Bukkit.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public void reloadCustomConfig()
|
||||
{
|
||||
ImageOnMap plugin = (ImageOnMap)Bukkit.getPluginManager().getPlugin("ImageOnMap");
|
||||
if (customConfigFile == null)
|
||||
{
|
||||
customConfigFile = new File(plugin.getDataFolder(), "poster.yml");
|
||||
}
|
||||
customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
|
||||
|
||||
// Look for defaults in the jar
|
||||
InputStream defConfigStream = plugin.getResource("poster.yml");
|
||||
if (defConfigStream != null)
|
||||
{
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||
customConfig.setDefaults(defConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public FileConfiguration getCustomConfig()
|
||||
{
|
||||
if (customConfig == null)
|
||||
{
|
||||
reloadCustomConfig();
|
||||
}
|
||||
return customConfig;
|
||||
}
|
||||
|
||||
public void saveCustomConfig()
|
||||
{
|
||||
ImageOnMap plugin = (ImageOnMap)Bukkit.getPluginManager().getPlugin("ImageOnMap");
|
||||
if (customConfig == null || customConfigFile == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
getCustomConfig().save(customConfigFile);
|
||||
} catch (IOException ex) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
134
src/fr/moribus/ImageOnMap/Map/PosterMap.java
Normal file
134
src/fr/moribus/ImageOnMap/Map/PosterMap.java
Normal file
@ -0,0 +1,134 @@
|
||||
package fr.moribus.ImageOnMap.Map;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
import fr.moribus.ImageOnMap.Poster;
|
||||
|
||||
public class PosterMap implements ImageMap
|
||||
{
|
||||
private SingleMap[] posterMap;
|
||||
private PosterData data;
|
||||
|
||||
public PosterMap(Image img, Player joueur)
|
||||
{
|
||||
Poster poster = new Poster((BufferedImage)img);
|
||||
BufferedImage[] imgs = poster.getPoster();
|
||||
posterMap = new SingleMap[imgs.length];
|
||||
|
||||
short[] idsMap = new short[posterMap.length];
|
||||
for(int i = 0; i < posterMap.length; i++)
|
||||
{
|
||||
SingleMap map = new SingleMap(imgs[i], joueur);
|
||||
posterMap[i] = map;
|
||||
idsMap[i] = map.getId();
|
||||
}
|
||||
|
||||
data = new PosterData(joueur.getName(), idsMap);
|
||||
}
|
||||
|
||||
public PosterMap(String id) throws Exception
|
||||
{
|
||||
data = new PosterData(id);
|
||||
|
||||
short[] ids = data.getIdMaps();
|
||||
posterMap = new SingleMap[ids.length];
|
||||
for(int i = 0; i < ids.length; i++)
|
||||
{
|
||||
SingleMap map = new SingleMap(ids[i]);
|
||||
posterMap[i] = map;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean load()
|
||||
{
|
||||
boolean ok;
|
||||
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
ok = posterMap[i].load();
|
||||
i++;
|
||||
}
|
||||
while(ok && i < posterMap.length);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save()
|
||||
{
|
||||
boolean ok;
|
||||
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
ok = posterMap[i].save();
|
||||
i++;
|
||||
}
|
||||
while(ok && i < posterMap.length);
|
||||
|
||||
data.save();
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void give(Inventory inv)
|
||||
{
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
posterMap[i].give(inv);
|
||||
i++;
|
||||
}
|
||||
while(i < posterMap.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNamed()
|
||||
{
|
||||
boolean ok;
|
||||
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
ok = posterMap[i].isNamed();
|
||||
i++;
|
||||
}
|
||||
while(ok && i < posterMap.length);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImage(Image image)
|
||||
{
|
||||
Poster poster = new Poster((BufferedImage)image);
|
||||
BufferedImage[] imgs = poster.getPoster();
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
posterMap[i].setImage(imgs[i]);
|
||||
i++;
|
||||
}
|
||||
while(i < imgs.length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player joueur)
|
||||
{
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
posterMap[i].send(joueur);
|
||||
i++;
|
||||
}
|
||||
while(i < posterMap.length);
|
||||
}
|
||||
|
||||
}
|
124
src/fr/moribus/ImageOnMap/Map/SingleMap.java
Normal file
124
src/fr/moribus/ImageOnMap/Map/SingleMap.java
Normal file
@ -0,0 +1,124 @@
|
||||
package fr.moribus.ImageOnMap.Map;
|
||||
|
||||
import java.awt.Image;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
import fr.moribus.ImageOnMap.Rendu;
|
||||
|
||||
public class SingleMap implements ImageMap
|
||||
{
|
||||
private MapData data;
|
||||
private MapView map;
|
||||
private boolean named;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public SingleMap(Image img, Player joueur)
|
||||
{
|
||||
map = Bukkit.createMap(joueur.getWorld());
|
||||
this.named = false;
|
||||
|
||||
data = new MapData(map.getId(), joueur.getName(), img, joueur.getWorld().getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public SingleMap(Image img, Player joueur, String name)
|
||||
{
|
||||
map = Bukkit.createMap(joueur.getWorld());
|
||||
|
||||
data = new MapData(map.getId(), joueur.getName(), img, joueur.getWorld().getName(), name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public SingleMap(short id) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
data = new MapData(id);
|
||||
data.load();
|
||||
map = Bukkit.getMap(id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save()
|
||||
{
|
||||
return data.save();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void give(Inventory inv)
|
||||
{
|
||||
ItemStack itemMap = new ItemStack(Material.MAP, 1, map.getId());
|
||||
if(isNamed())
|
||||
{
|
||||
ItemMeta meta = itemMap.getItemMeta();
|
||||
meta.setDisplayName(data.getNom());
|
||||
itemMap.setItemMeta(meta);
|
||||
}
|
||||
inv.addItem(itemMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean load()
|
||||
{
|
||||
if(map != null)
|
||||
{
|
||||
SingleMap.SupprRendu(map);
|
||||
map.addRenderer(new Rendu(data.getImage()));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNamed()
|
||||
{
|
||||
return named;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public short getId()
|
||||
{
|
||||
return map.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setImage(Image image)
|
||||
{
|
||||
data.setImage(image);
|
||||
load();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Player joueur)
|
||||
{
|
||||
joueur.sendMap(map);
|
||||
}
|
||||
|
||||
public static void SupprRendu(MapView map)
|
||||
{
|
||||
if (map.getRenderers().size() > 0)
|
||||
{
|
||||
int i = 0, t = map.getRenderers().size();
|
||||
while (i < t)
|
||||
{
|
||||
map.removeRenderer(map.getRenderers().get(i));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,7 +2,6 @@ package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@ -13,6 +12,10 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
import fr.moribus.ImageOnMap.Map.ImageMap;
|
||||
import fr.moribus.ImageOnMap.Map.PosterMap;
|
||||
import fr.moribus.ImageOnMap.Map.SingleMap;
|
||||
|
||||
public class MapToolCommand implements CommandExecutor
|
||||
{
|
||||
short id;
|
||||
@ -26,7 +29,6 @@ public class MapToolCommand implements CommandExecutor
|
||||
plugin = p;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String arg2, String[] arg3)
|
||||
{
|
||||
@ -36,7 +38,7 @@ public class MapToolCommand implements CommandExecutor
|
||||
|
||||
String nomCmd = arg2;
|
||||
joueur = (Player) sender;
|
||||
inv = (Inventory) joueur.getInventory();
|
||||
inv = joueur.getInventory();
|
||||
|
||||
if(arg3.length < 1)
|
||||
{
|
||||
@ -59,29 +61,87 @@ public class MapToolCommand implements CommandExecutor
|
||||
return true;
|
||||
}
|
||||
|
||||
SavedMap smap = new SavedMap(plugin, id);
|
||||
//map = ImgUtility.getMap(plugin, id);
|
||||
|
||||
if(!smap.LoadMap())
|
||||
SingleMap smap;
|
||||
try
|
||||
{
|
||||
if(joueur.isOp())
|
||||
joueur.sendMessage(ChatColor.RED+ "Can't retrieve the map ! Check if map"+ id+ " exists in your maps.yml or if the dat file in the world folder exists");
|
||||
smap = new SingleMap(id);
|
||||
|
||||
if(!smap.load())
|
||||
{
|
||||
if(joueur.isOp())
|
||||
joueur.sendMessage(ChatColor.RED+ "Can't retrieve the map ! Check if map"+ id+ " exists in your maps.yml or if the dat file in the world folder exists");
|
||||
else
|
||||
joueur.sendMessage(ChatColor.RED+ "ERROR: This map doesn't exists");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
joueur.sendMessage(ChatColor.RED+ "ERROR: This map doesn't exists");
|
||||
return true;
|
||||
{
|
||||
if(inv.firstEmpty() == -1)
|
||||
{
|
||||
joueur.sendMessage("Your inventory is full, you can't take the map !");
|
||||
return true;
|
||||
}
|
||||
|
||||
smap.give(joueur.getInventory());
|
||||
joueur.sendMessage("Map "+ ChatColor.ITALIC+ id+ ChatColor.RESET+ " was added in your inventory.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(inv.firstEmpty() == -1)
|
||||
catch (Exception e)
|
||||
{
|
||||
joueur.sendMessage("Your inventory is full, you can't take the map !");
|
||||
joueur.sendMessage(ChatColor.RED+ "ERROR while loading maps");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
else if(arg3[0].equalsIgnoreCase("set"))
|
||||
{
|
||||
ImageMap smap;
|
||||
try
|
||||
{
|
||||
if(arg3[1].startsWith("poster"))
|
||||
{
|
||||
smap = new PosterMap(arg3[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
id = Short.parseShort(arg3[1]);
|
||||
smap = new SingleMap(id);
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException err)
|
||||
{
|
||||
joueur.sendMessage("you must enter a number !");
|
||||
return true;
|
||||
} catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
joueur.sendMessage(ChatColor.RED+ "ERROR while loading maps");
|
||||
return true;
|
||||
}
|
||||
|
||||
map = Bukkit.getMap(id);
|
||||
inv.addItem(new ItemStack(Material.MAP, 1, map.getId()));
|
||||
joueur.sendMap(map);
|
||||
joueur.sendMessage("Map "+ ChatColor.ITALIC+ id+ ChatColor.RESET+ " was added in your inventory.");
|
||||
|
||||
if(!arg3[2].startsWith("http"))
|
||||
{
|
||||
joueur.sendMessage("You must enter a valid URL.");
|
||||
return true;
|
||||
}
|
||||
else if(arg3[2].startsWith("https"))
|
||||
{
|
||||
joueur.sendMessage("WARNING: you have entered a secure HTTP link, ImageOnMap can't guarantee " +
|
||||
"that the image is downloadable");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
TacheTraitementMajMap tache = new TacheTraitementMajMap(smap, arg3[2], joueur);
|
||||
tache.runTaskTimer(plugin, 0, 5);
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -158,7 +158,8 @@ public class MetricsLite {
|
||||
|
||||
private boolean firstPost = true;
|
||||
|
||||
public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// This has to be synchronized or it can collide with the disable method.
|
||||
synchronized (optOutLock) {
|
||||
|
@ -6,13 +6,13 @@ import java.util.HashMap;
|
||||
/* Class which represents a picture cut into several parts */
|
||||
public class Poster
|
||||
{
|
||||
BufferedImage src;
|
||||
BufferedImage ImgDecoupe[];
|
||||
HashMap<Integer, String> NumeroMap;
|
||||
int nbPartie;
|
||||
int nbColonne;
|
||||
private BufferedImage src;
|
||||
private BufferedImage[] ImgDecoupe;
|
||||
private HashMap<Integer, String> NumeroMap;
|
||||
private int nbPartie;
|
||||
private int nbColonne;
|
||||
|
||||
Poster(BufferedImage img)
|
||||
public Poster(BufferedImage img)
|
||||
{
|
||||
src = img;
|
||||
NumeroMap = new HashMap<Integer, String>();
|
||||
|
@ -11,15 +11,14 @@ import org.bukkit.map.MapView;
|
||||
public class Rendu extends MapRenderer implements Runnable
|
||||
{
|
||||
|
||||
boolean estRendu;
|
||||
Image touhou;
|
||||
private Thread TRendu;
|
||||
public MapCanvas canvas;
|
||||
private boolean estRendu;
|
||||
private Image imageARendre;
|
||||
private MapCanvas canvas;
|
||||
|
||||
public Rendu(Image img)
|
||||
{
|
||||
estRendu = false;
|
||||
touhou = img;
|
||||
setImageARendre(img);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,19 +29,30 @@ public class Rendu extends MapRenderer implements Runnable
|
||||
|
||||
if (!estRendu) // Si la map a déjà été rendu, on n'entre plus dans la fonction, ce qui évite de surcharger le serveur
|
||||
{
|
||||
// On instancie et démarre le thread de rendu
|
||||
TRendu = new Thread(this);
|
||||
TRendu.start();
|
||||
run();
|
||||
estRendu = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Le chargement et le rendu de l'image se font dans un thread afin d'éviter le lag..
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// on dessine l'image redimensionnée dans le canvas (et donc, sur la map !)
|
||||
canvas.drawImage(0, 0, touhou);
|
||||
canvas.drawImage(0, 0, getImageARendre());
|
||||
|
||||
}
|
||||
|
||||
public Image getImageARendre()
|
||||
{
|
||||
return imageARendre;
|
||||
}
|
||||
|
||||
public void setImageARendre(Image imageARendre)
|
||||
{
|
||||
if(imageARendre != null)
|
||||
{
|
||||
this.imageARendre = imageARendre;
|
||||
estRendu = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -124,7 +124,8 @@ public class SavedPoster
|
||||
* le fichier conf des Posters (poster.yml).
|
||||
* Je les ai juste copié depuis un tuto du wiki Bukkit...
|
||||
*/
|
||||
public void reloadCustomConfig()
|
||||
@SuppressWarnings("deprecation")
|
||||
public void reloadCustomConfig()
|
||||
{
|
||||
if (customConfigFile == null)
|
||||
{
|
||||
|
@ -11,6 +11,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import fr.moribus.ImageOnMap.Map.SingleMap;
|
||||
|
||||
public class SendMapOnFrameEvent implements Listener
|
||||
{
|
||||
ImageOnMap plugin;
|
||||
@ -23,7 +25,6 @@ public class SendMapOnFrameEvent implements Listener
|
||||
plugin = plug;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onChunkLoad(ChunkLoadEvent event)
|
||||
{
|
||||
@ -39,8 +40,15 @@ public class SendMapOnFrameEvent implements Listener
|
||||
ItemStack stack = frame.getItem();
|
||||
if(stack.getType() == Material.MAP && !ListeId.contains(stack.getDurability()))
|
||||
{
|
||||
SavedMap map = new SavedMap(plugin, stack.getDurability());
|
||||
map.LoadMap();
|
||||
try
|
||||
{
|
||||
new SingleMap(stack.getDurability()).load();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,6 +10,8 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import fr.moribus.ImageOnMap.Map.SingleMap;
|
||||
|
||||
|
||||
public class SendMapOnInvEvent implements Listener
|
||||
{
|
||||
@ -42,13 +43,14 @@ public class SendMapOnInvEvent implements Listener
|
||||
{
|
||||
if(plugin.getCustomConfig().getStringList(s).get(0).equals(String.valueOf(stack.getDurability())))
|
||||
{
|
||||
SavedMap map = new SavedMap(plugin, Short.valueOf(plugin.getCustomConfig().getStringList(s).get(0)));
|
||||
|
||||
if(!map.LoadMap())
|
||||
plugin.getLogger().log(Level.WARNING, "Unable to load map " +stack.getDurability());
|
||||
else
|
||||
try
|
||||
{
|
||||
break;
|
||||
new SingleMap(stack.getDurability()).load();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
27
src/fr/moribus/ImageOnMap/TacheTraitementMajMap.java
Normal file
27
src/fr/moribus/ImageOnMap/TacheTraitementMajMap.java
Normal file
@ -0,0 +1,27 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.moribus.ImageOnMap.Map.ImageMap;
|
||||
|
||||
public class TacheTraitementMajMap extends TacheTraitementMap
|
||||
{
|
||||
private ImageMap m;
|
||||
|
||||
public TacheTraitementMajMap(ImageMap m, String u, Player joueur)
|
||||
{
|
||||
super(u);
|
||||
setJoueur(joueur);
|
||||
this.m = m;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traiterMap(BufferedImage img)
|
||||
{
|
||||
m.setImage(img);
|
||||
m.save();
|
||||
m.send(getJoueur());
|
||||
}
|
||||
}
|
@ -1,80 +1,106 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.map.MapView;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class TacheTraitementMap extends BukkitRunnable
|
||||
public abstract class TacheTraitementMap extends BukkitRunnable
|
||||
{
|
||||
int i;
|
||||
ImgPlayer joueur;
|
||||
ImageRendererThread renduImg;
|
||||
PlayerInventory inv;
|
||||
ItemStack map;
|
||||
ImageOnMap plugin;
|
||||
boolean resized, renamed;
|
||||
|
||||
TacheTraitementMap(Player j, String u, ImageOnMap plug, boolean rs, boolean rn)
|
||||
private Player joueur;
|
||||
private DownloadImageThread renduImg;
|
||||
private PlayerInventory inv;
|
||||
private ItemStack map;
|
||||
private ImageOnMap plugin;
|
||||
private boolean resized, renamed;
|
||||
private ExecutorService dlImg;
|
||||
private Future<BufferedImage> futurDlImg;
|
||||
private int compteurExec;
|
||||
|
||||
protected TacheTraitementMap(String u)
|
||||
{
|
||||
i = 0;
|
||||
joueur = new ImgPlayer(j);
|
||||
renduImg = new ImageRendererThread(u, rs);
|
||||
renduImg.start();
|
||||
renduImg = new DownloadImageThread(u);
|
||||
dlImg = Executors.newSingleThreadExecutor();
|
||||
futurDlImg = dlImg.submit(renduImg);
|
||||
plugin = (ImageOnMap) Bukkit.getPluginManager().getPlugin("ImageOnMap");
|
||||
}
|
||||
|
||||
public TacheTraitementMap(Player j, String u, boolean rs, boolean rn)
|
||||
{
|
||||
this(u);
|
||||
joueur = j;
|
||||
inv = joueur.getInventory();
|
||||
plugin = plug;
|
||||
resized = rs;
|
||||
renamed = rn;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(!renduImg.getStatut())
|
||||
compteurExec = 0;
|
||||
if(!futurDlImg.isDone())
|
||||
{
|
||||
//joueur.sendMessage("Nombre d'exécution depuis le lancement du timer : " + i);
|
||||
i++;
|
||||
if(renduImg.erreur)
|
||||
{
|
||||
joueur.sendMessage("There was a problem while fetching image. Check your URL.");
|
||||
cancel();
|
||||
}
|
||||
if(i > 42)
|
||||
compteurExec++;
|
||||
if(compteurExec > 20)
|
||||
{
|
||||
joueur.sendMessage("TIMEOUT: the render took too many time");
|
||||
futurDlImg.cancel(true);
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cancel();
|
||||
int nbImage = renduImg.getImg().length;
|
||||
if (plugin.getConfig().getInt("Limit-map-by-server") != 0 && nbImage + ImgUtility.getNombreDeMaps(plugin) > plugin.getConfig().getInt("Limit-map-by-server"))
|
||||
{
|
||||
joueur.sendMessage("ERROR: cannot render "+ nbImage +" picture(s): the limit of maps per server would be exceeded.");
|
||||
return;
|
||||
}
|
||||
if(joueur.hasPermission("imageonmap.nolimit"))
|
||||
if(!futurDlImg.isCancelled())
|
||||
{
|
||||
cancel();
|
||||
int nbImage = 1;
|
||||
if (plugin.getConfig().getInt("Limit-map-by-server") != 0 && nbImage + ImgUtility.getNombreDeMaps(plugin) > plugin.getConfig().getInt("Limit-map-by-server"))
|
||||
{
|
||||
joueur.sendMessage("ERROR: cannot render "+ nbImage +" picture(s): the limit of maps per server would be exceeded.");
|
||||
return;
|
||||
}
|
||||
if(joueur.hasPermission("imageonmap.nolimit"))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plugin.getConfig().getInt("Limit-map-by-player") != 0 && nbImage + ImgUtility.getNombreDeMapsParJoueur(plugin, joueur.getName()) > plugin.getConfig().getInt("Limit-map-by-player"))
|
||||
{
|
||||
joueur.sendMessage(ChatColor.RED +"ERROR: cannot render "+ nbImage +" picture(s): the limit of maps allowed for you (per player) would be exceeded.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
joueur.sendMessage("Bingo ! Image téléchargée.");
|
||||
try
|
||||
{
|
||||
traiterMap(futurDlImg.get());
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
joueur.sendMessage(ChatColor.RED+ "ERROR: download task has been interrupted. Make sure your URL is valid.");
|
||||
}
|
||||
catch (ExecutionException e)
|
||||
{
|
||||
joueur.sendMessage(ChatColor.RED+ "Your image can't be downloaded. Please check your URL");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (plugin.getConfig().getInt("Limit-map-by-player") != 0 && nbImage + ImgUtility.getNombreDeMapsParJoueur(plugin, joueur.getName()) > plugin.getConfig().getInt("Limit-map-by-player"))
|
||||
{
|
||||
joueur.sendMessage(ChatColor.RED +"ERROR: cannot render "+ nbImage +" picture(s): the limit of maps allowed for you (per player) would be exceeded.");
|
||||
return;
|
||||
}
|
||||
joueur.sendMessage(ChatColor.RED+ "An error occured. See the console for details");
|
||||
}
|
||||
MapView carte;
|
||||
|
||||
|
||||
/*MapView carte;
|
||||
|
||||
ArrayList<ItemStack> restant = new ArrayList<ItemStack>();
|
||||
short[] ids = new short[nbImage];
|
||||
@ -84,7 +110,7 @@ public class TacheTraitementMap extends BukkitRunnable
|
||||
carte = Bukkit.getMap(joueur.getItemInHand().getDurability());
|
||||
else
|
||||
carte = Bukkit.createMap(joueur.getWorld());
|
||||
ImageRendererThread.SupprRendu(carte);
|
||||
MapCreateThread.SupprRendu(carte);
|
||||
carte.addRenderer(new Rendu(renduImg.getImg()[i]));
|
||||
map = new ItemStack(Material.MAP, 1, carte.getId());
|
||||
if(nbImage > 1)
|
||||
@ -120,8 +146,74 @@ public class TacheTraitementMap extends BukkitRunnable
|
||||
joueur.sendMessage("Render finished");
|
||||
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 getrest");
|
||||
plugin.setRemainingMaps(joueur.getName(), restant);
|
||||
plugin.setRemainingMaps(joueur.getName(), restant);*/
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void traiterMap(BufferedImage img);
|
||||
|
||||
protected Player getJoueur() {
|
||||
return joueur;
|
||||
}
|
||||
|
||||
protected void setJoueur(Player joueur) {
|
||||
this.joueur = joueur;
|
||||
}
|
||||
|
||||
protected DownloadImageThread getRenduImg() {
|
||||
return renduImg;
|
||||
}
|
||||
|
||||
protected void setRenduImg(DownloadImageThread renduImg) {
|
||||
this.renduImg = renduImg;
|
||||
}
|
||||
|
||||
protected PlayerInventory getInv() {
|
||||
return inv;
|
||||
}
|
||||
|
||||
protected void setInv(PlayerInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
protected ItemStack getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
protected void setMap(ItemStack map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
protected ImageOnMap getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
protected void setPlugin(ImageOnMap plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
protected boolean isResized() {
|
||||
return resized;
|
||||
}
|
||||
|
||||
protected void setResized(boolean resized) {
|
||||
this.resized = resized;
|
||||
}
|
||||
|
||||
protected boolean isRenamed() {
|
||||
return renamed;
|
||||
}
|
||||
|
||||
protected void setRenamed(boolean renamed) {
|
||||
this.renamed = renamed;
|
||||
}
|
||||
|
||||
protected int getCompteurExec() {
|
||||
return compteurExec;
|
||||
}
|
||||
|
||||
protected void setCompteurExec(int compteurExec) {
|
||||
this.compteurExec = compteurExec;
|
||||
}
|
||||
|
||||
}
|
||||
|
26
src/fr/moribus/ImageOnMap/TacheTraitementNouvelleMap.java
Normal file
26
src/fr/moribus/ImageOnMap/TacheTraitementNouvelleMap.java
Normal file
@ -0,0 +1,26 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.moribus.ImageOnMap.Map.PosterMap;
|
||||
|
||||
public class TacheTraitementNouvelleMap extends TacheTraitementMap
|
||||
{
|
||||
|
||||
public TacheTraitementNouvelleMap(Player j, String u, boolean rs, boolean rn)
|
||||
{
|
||||
super(j, u, rs, rn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void traiterMap(BufferedImage img)
|
||||
{
|
||||
PosterMap m = new PosterMap(img, getJoueur());
|
||||
m.load();
|
||||
m.give(getJoueur().getInventory());
|
||||
m.save();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user