mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-11-25 11:35:35 +01:00
Ajout enregistrement du monde de la map
This commit is contained in:
parent
2828445706
commit
250e080394
11
.classpath
Normal file
11
.classpath
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="lib" path="/home/moribus/Téléchargements/bukkit-1.7.2-R0.3-20140106.202257-6.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/bin
|
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ImageOnMap</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
11
.settings/org.eclipse.jdt.core.prefs
Normal file
11
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
Binary file not shown.
Binary file not shown.
@ -1,6 +1,6 @@
|
||||
name: ImageOnMap
|
||||
main: fr.moribus.ImageOnMap.ImageOnMap
|
||||
version: 2.5.1
|
||||
version: 2.6.1
|
||||
|
||||
commands:
|
||||
tomap:
|
||||
|
@ -24,9 +24,18 @@ public final class ImageOnMap extends JavaPlugin
|
||||
// accessible de partout dans le plugin..
|
||||
private HashMap<String, ArrayList<ItemStack>> cache = new HashMap<String, ArrayList<ItemStack>>();
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
|
||||
//File map = new File("/home/moribus/Projet/Serveur de dev/world/data/map_1125.dat");
|
||||
//map.delete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
getLogger().info("World name: "+ getServer().getWorlds().get(0).getName());
|
||||
// On crée si besoin le dossier où les images seront stockées
|
||||
dossierCree = ImgUtility.CreeRepImg(this);
|
||||
|
||||
@ -42,7 +51,7 @@ public final class ImageOnMap extends JavaPlugin
|
||||
{
|
||||
MetricsLite metrics = new MetricsLite(this);
|
||||
metrics.start();
|
||||
System.out.println("Metrics launched for ImageOnMap");
|
||||
getLogger().info("Metrics launched for ImageOnMap");
|
||||
} catch (IOException e) {
|
||||
// Failed to submit the stats :-(
|
||||
}
|
||||
@ -57,7 +66,7 @@ public final class ImageOnMap extends JavaPlugin
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("[ImageOnMap] An error occured ! Unable to create Image folder. Plugin will NOT work !");
|
||||
getLogger().info("[ImageOnMap] An error occured ! Unable to create Image folder. Plugin will NOT work !");
|
||||
this.setEnabled(false);
|
||||
}
|
||||
|
||||
@ -66,7 +75,7 @@ public final class ImageOnMap extends JavaPlugin
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
System.out.println("Stopping ImageOnMap");
|
||||
getLogger().info("Stopping ImageOnMap");
|
||||
}
|
||||
|
||||
public void ChargerMap()
|
||||
@ -86,9 +95,9 @@ public final class ImageOnMap extends JavaPlugin
|
||||
}
|
||||
|
||||
}
|
||||
System.out.println(nbMap +" maps was loaded");
|
||||
getLogger().info(nbMap +" maps was loaded");
|
||||
if(nbErr != 0)
|
||||
System.out.println(nbErr +" maps can't be loaded");
|
||||
getLogger().info(nbErr +" maps can't be loaded");
|
||||
}
|
||||
|
||||
/* Méthodes pour charger / recharger / sauvegarder
|
||||
|
@ -1,109 +0,0 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
|
||||
public class ImageRenderer extends Thread
|
||||
{
|
||||
private String URL;
|
||||
private BufferedImage imgSrc;
|
||||
private Poster img;
|
||||
private boolean estPrete = false;
|
||||
boolean erreur = false;
|
||||
|
||||
ImageRenderer(String u)
|
||||
{
|
||||
URL = u;
|
||||
}
|
||||
|
||||
public Poster getImg()
|
||||
{
|
||||
if (estPrete)
|
||||
return img;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Boolean getStatut()
|
||||
{
|
||||
return estPrete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
imgSrc = ImageIO.read(URI.create(URL).toURL().openStream());
|
||||
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
|
||||
img = new Poster(canvas);
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
erreur = true;
|
||||
}
|
||||
|
||||
estPrete = true;
|
||||
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
140
src/fr/moribus/ImageOnMap/ImageRendererThread.java
Normal file
140
src/fr/moribus/ImageOnMap/ImageRendererThread.java
Normal file
@ -0,0 +1,140 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
|
||||
public class ImageRendererThread extends Thread
|
||||
{
|
||||
private String URL;
|
||||
private BufferedImage imgSrc;
|
||||
private BufferedImage[] img;
|
||||
private Poster poster;
|
||||
private boolean estPrete = false, resized;
|
||||
boolean erreur = false;
|
||||
|
||||
public boolean isErreur()
|
||||
{
|
||||
return erreur;
|
||||
}
|
||||
|
||||
ImageRendererThread(String u, boolean r)
|
||||
{
|
||||
URL = u;
|
||||
resized = r;
|
||||
}
|
||||
|
||||
public BufferedImage[] getImg()
|
||||
{
|
||||
if (estPrete)
|
||||
return img;
|
||||
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public HashMap<Integer, String> getNumeroMap()
|
||||
{
|
||||
return poster.NumeroMap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Boolean getStatut()
|
||||
{
|
||||
return estPrete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
imgSrc = ImageIO.read(URI.create(URL).toURL().openStream());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
erreur = true;
|
||||
}
|
||||
|
||||
estPrete = true;
|
||||
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,11 +12,12 @@ public class ImageRenduCommande implements CommandExecutor
|
||||
|
||||
Player joueur;
|
||||
boolean renderName, imgSvg;
|
||||
ImageOnMap ca;
|
||||
ImageOnMap plugin;
|
||||
boolean resize;
|
||||
|
||||
public ImageRenduCommande(ImageOnMap plugin)
|
||||
public ImageRenduCommande(ImageOnMap p)
|
||||
{
|
||||
ca = plugin;
|
||||
plugin = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -28,6 +29,7 @@ public class ImageRenduCommande implements CommandExecutor
|
||||
return false;
|
||||
|
||||
joueur = (Player) sender;
|
||||
resize = false;
|
||||
|
||||
if(joueur.hasPermission("imageonmap.userender"))
|
||||
{
|
||||
@ -45,8 +47,22 @@ public class ImageRenduCommande implements CommandExecutor
|
||||
return false;
|
||||
}
|
||||
|
||||
TacheTraitementMap tache = new TacheTraitementMap(joueur, arg3[0], ca);
|
||||
tache.runTaskTimer(ca, 0, 10);
|
||||
/*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 && arg3[1].equalsIgnoreCase("resize"))
|
||||
{
|
||||
resize = true;
|
||||
}
|
||||
|
||||
|
||||
TacheTraitementMap tache = new TacheTraitementMap(joueur, arg3[0], plugin, resize);
|
||||
tache.runTaskTimer(plugin, 0, 10);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -195,7 +195,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");
|
||||
ImageRenderer.SupprRendu(carte);
|
||||
ImageRendererThread.SupprRendu(carte);
|
||||
plugin.getCustomConfig().set(s, null);
|
||||
plugin.saveCustomConfig();
|
||||
File map = new File("./plugins/ImageOnMap/Image/" + s + ".png");
|
||||
|
@ -24,6 +24,7 @@ public class Poster
|
||||
return ImgDecoupe;
|
||||
}
|
||||
|
||||
|
||||
public int getNbColonne()
|
||||
{
|
||||
return nbColonne;
|
||||
|
@ -15,17 +15,18 @@ import org.bukkit.map.MapView;
|
||||
public class SavedMap
|
||||
{
|
||||
ImageOnMap plugin;
|
||||
String nomImg, nomJoueur;
|
||||
String nomImg, nomJoueur, nomMonde;
|
||||
short idMap;
|
||||
BufferedImage image;
|
||||
|
||||
SavedMap(ImageOnMap plug, String nomJ, short id, BufferedImage img)
|
||||
SavedMap(ImageOnMap plug, String nomJ, short id, BufferedImage img, String nomM)
|
||||
{
|
||||
plugin = plug;
|
||||
nomJoueur = nomJ;
|
||||
idMap = id;
|
||||
image = img;
|
||||
nomImg = "map" + id;
|
||||
nomMonde = nomM;
|
||||
}
|
||||
|
||||
SavedMap(ImageOnMap plug, short id)
|
||||
@ -59,7 +60,7 @@ public class SavedMap
|
||||
|
||||
Boolean SaveMap()
|
||||
{
|
||||
System.out.println("Saving map " + idMap);
|
||||
plugin.getLogger().info("Saving map " + idMap);
|
||||
|
||||
// Enregistrement de l'image sur le disque dur
|
||||
try
|
||||
@ -76,6 +77,7 @@ public class SavedMap
|
||||
liste.add(String.valueOf(idMap));
|
||||
liste.add(nomImg);
|
||||
liste.add(nomJoueur);
|
||||
liste.add(nomMonde);
|
||||
plugin.getCustomConfig().set(nomImg, liste);
|
||||
plugin.saveCustomConfig();
|
||||
return true;
|
||||
@ -87,7 +89,7 @@ public class SavedMap
|
||||
MapView carte = Bukkit.getMap(idMap);
|
||||
if(carte != null)
|
||||
{
|
||||
ImageRenderer.SupprRendu(carte);
|
||||
ImageRendererThread.SupprRendu(carte);
|
||||
carte.addRenderer(new Rendu(image));
|
||||
return true;
|
||||
}
|
||||
|
@ -16,19 +16,21 @@ public class TacheTraitementMap extends BukkitRunnable
|
||||
{
|
||||
int i;
|
||||
Player joueur;
|
||||
ImageRenderer renduImg;
|
||||
ImageRendererThread renduImg;
|
||||
PlayerInventory inv;
|
||||
ItemStack map;
|
||||
ImageOnMap plugin;
|
||||
boolean resized;
|
||||
|
||||
TacheTraitementMap(Player j, String u, ImageOnMap plug)
|
||||
TacheTraitementMap(Player j, String u, ImageOnMap plug, boolean r)
|
||||
{
|
||||
i = 0;
|
||||
joueur = j;
|
||||
renduImg = new ImageRenderer(u);
|
||||
renduImg = new ImageRendererThread(u, r);
|
||||
renduImg.start();
|
||||
inv = joueur.getInventory();
|
||||
plugin = plug;
|
||||
resized = r;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -39,7 +41,7 @@ public class TacheTraitementMap extends BukkitRunnable
|
||||
{
|
||||
//joueur.sendMessage("Nombre d'exécution depuis le lancement du timer : " + i);
|
||||
i++;
|
||||
if(i > 42)
|
||||
if(renduImg.isErreur() || i > 42)
|
||||
{
|
||||
joueur.sendMessage("TIMEOUT: the render took too many time");
|
||||
cancel();
|
||||
@ -48,7 +50,7 @@ public class TacheTraitementMap extends BukkitRunnable
|
||||
else
|
||||
{
|
||||
cancel();
|
||||
int nbImage = renduImg.getImg().getPoster().length;
|
||||
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.");
|
||||
@ -65,17 +67,21 @@ public class TacheTraitementMap extends BukkitRunnable
|
||||
for (int i = 0; i < nbImage; i++)
|
||||
{
|
||||
carte = Bukkit.createMap(joueur.getWorld());
|
||||
ImageRenderer.SupprRendu(carte);
|
||||
carte.addRenderer(new Rendu(renduImg.getImg().getPoster()[i]));
|
||||
ImageRendererThread.SupprRendu(carte);
|
||||
carte.addRenderer(new Rendu(renduImg.getImg()[i]));
|
||||
map = new ItemStack(Material.MAP, 1, carte.getId());
|
||||
ItemMeta meta = map.getItemMeta();
|
||||
meta.setDisplayName("Map (" +renduImg.getImg().NumeroMap.get(i) +")");
|
||||
map.setItemMeta(meta);
|
||||
if(!resized)
|
||||
{
|
||||
ItemMeta meta = map.getItemMeta();
|
||||
meta.setDisplayName("Map (" +renduImg.getNumeroMap().get(i) +")");
|
||||
map.setItemMeta(meta);
|
||||
}
|
||||
|
||||
|
||||
ImgUtility.AddMap(map, inv, restant);
|
||||
|
||||
//Svg de la map
|
||||
SavedMap svg = new SavedMap(plugin, joueur.getName(), carte.getId(), renduImg.getImg().getPoster()[i]);
|
||||
SavedMap svg = new SavedMap(plugin, joueur.getName(), carte.getId(), renduImg.getImg()[i], joueur.getWorld().getName());
|
||||
svg.SaveMap();
|
||||
joueur.sendMap(carte);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user