mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-01-25 00:31:25 +01:00
Ajout de la commande /rmmap
This commit is contained in:
parent
b9393d7ec5
commit
aa9c7df875
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +1,11 @@
|
||||
name: ImageOnMap
|
||||
main: fr.moribus.ImageOnMap.ImageOnMap
|
||||
version: 1.0
|
||||
version: 1.2
|
||||
|
||||
commands:
|
||||
tomap:
|
||||
description: render an image in a map
|
||||
usage: /<command> [URL] [true or false]
|
||||
usage: /<command> [URL]
|
||||
rmmap:
|
||||
description: remove an image
|
||||
usage: /<command>
|
@ -1,5 +1,6 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -8,12 +9,18 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class ImageOnMap extends JavaPlugin
|
||||
{
|
||||
|
||||
File dossier;
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
dossier = new File(getDataFolder().getPath() + "/Image");
|
||||
if (!dossier.exists())
|
||||
{
|
||||
dossier.mkdir();
|
||||
}
|
||||
System.out.println("Loading ImageOnMap");
|
||||
getCommand("tomap").setExecutor(new ImageCommande(this));
|
||||
getCommand("tomap").setExecutor(new ImageRenduCommande(this));
|
||||
getCommand("rmmap").setExecutor(new ImageSupprCommande(this));
|
||||
this.saveDefaultConfig();
|
||||
ChargerMap();
|
||||
}
|
||||
@ -24,16 +31,16 @@ public final class ImageOnMap extends JavaPlugin
|
||||
System.out.println("Stopping ImageOnMap");
|
||||
}
|
||||
|
||||
void ChargerMap()
|
||||
public void ChargerMap()
|
||||
{
|
||||
Set<String> cle = getConfig().getKeys(false);
|
||||
for (String s: cle)
|
||||
{
|
||||
System.out.println("Loading" + s);
|
||||
System.out.println("Loading " + s);
|
||||
@SuppressWarnings("deprecation")
|
||||
MapView carte = Bukkit.getMap(Short.parseShort(getConfig().getStringList(s).get(0)));
|
||||
Rendu.SupprRendu(carte);
|
||||
carte.addRenderer(new Rendu("./plugins/ImageOnMap/" + getConfig().getStringList(s).get(1) + ".png", getConfig().getStringList(s).get(2)));
|
||||
carte.addRenderer(new Rendu("./plugins/ImageOnMap/Image/" + getConfig().getStringList(s).get(1) + ".png", getConfig().getStringList(s).get(2)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,27 +1,23 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.map.MapView;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ImageCommande implements CommandExecutor
|
||||
public class ImageRenduCommande implements CommandExecutor
|
||||
{
|
||||
|
||||
Player joueur;
|
||||
Plugin ca;
|
||||
ImageOnMap ca;
|
||||
boolean imgSvg;
|
||||
|
||||
public ImageCommande(Plugin plugin)
|
||||
public ImageRenduCommande(ImageOnMap plugin)
|
||||
{
|
||||
ca = plugin;
|
||||
}
|
||||
@ -32,50 +28,39 @@ public class ImageCommande implements CommandExecutor
|
||||
String[] arg3)
|
||||
{
|
||||
// On vérifie si celui qui exécute la commande est bien un joueur
|
||||
if (sender instanceof Player)
|
||||
joueur = (Player) sender;
|
||||
else if (sender instanceof ConsoleCommandSender)
|
||||
{System.out.println(ChatColor.RED + "Cette commande ne peut être utilisée dans la console !"); return true;}
|
||||
else if (sender instanceof BlockCommandSender)
|
||||
{System.out.println(ChatColor.RED + "Cette commande ne peut être utilisée par un bloc-commande !"); return true;}
|
||||
else
|
||||
{System.out.println(ChatColor.RED + "Cette commande ne peut être lancée de cette façon !"); return true;}
|
||||
if (!ImgUtility.VerifierIdentite(sender))
|
||||
return false;
|
||||
|
||||
if (arg3.length < 2)
|
||||
joueur = (Player) sender;
|
||||
|
||||
if(!joueur.hasPermission("imageonmap.userender") || !joueur.isOp())
|
||||
{
|
||||
joueur.sendMessage("You must enter image url, and true if you want image to be persistant (false otherwise)");
|
||||
joueur.sendMessage("You are not allowed to use this command ( " + arg1.getName() + " )!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if(joueur.getItemInHand().getType() != Material.MAP)
|
||||
{
|
||||
joueur.sendMessage(ChatColor.RED + "Vous devez tenir une map en main !!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arg3.length < 1)
|
||||
{
|
||||
joueur.sendMessage(ChatColor.RED + "You must enter image url");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (arg3[1].contains("true"))
|
||||
imgSvg = true;
|
||||
else
|
||||
imgSvg = false;
|
||||
|
||||
imgSvg = true;
|
||||
// On crée une map
|
||||
Rendu ren = new Rendu(arg3[0], imgSvg);
|
||||
MapView carte = Bukkit.createMap(joueur.getWorld());
|
||||
Rendu ren = new Rendu(arg3[0], imgSvg, ca);
|
||||
MapView carte = Bukkit.getMap(joueur.getItemInHand().getDurability());
|
||||
Rendu.SupprRendu(carte);
|
||||
carte.addRenderer(ren);
|
||||
joueur.setItemInHand(new ItemStack(Material.MAP, 1, carte.getId()));
|
||||
|
||||
if (imgSvg)
|
||||
{
|
||||
SvgMap(carte.getId(), "map" + carte.getId(), joueur.getName());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SvgMap(int IdMap, String nomImage, String nomJoueur)
|
||||
{
|
||||
System.out.println("Sauvegarde de la map..");
|
||||
ArrayList<String> liste = new ArrayList<String>();
|
||||
liste.add(String.valueOf(IdMap));
|
||||
liste.add(nomImage);
|
||||
liste.add(nomJoueur);
|
||||
ca.getConfig().set("map" + IdMap, liste);
|
||||
ca.saveConfig();
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
@ -25,12 +26,15 @@ public class Rendu extends MapRenderer implements Runnable
|
||||
MapView carte;
|
||||
String URLImage, nomJoueur;
|
||||
Player joueur;
|
||||
boolean hasFail;
|
||||
ImageOnMap plugin;
|
||||
|
||||
public Rendu(String url, boolean svg)
|
||||
public Rendu(String url, boolean svg, ImageOnMap plug)
|
||||
{
|
||||
estRendu = true;
|
||||
estSVGee = svg;
|
||||
URLImage = url;
|
||||
plugin = plug;
|
||||
}
|
||||
|
||||
public Rendu(String url, String pseudo)
|
||||
@ -59,6 +63,7 @@ public class Rendu extends MapRenderer implements Runnable
|
||||
}
|
||||
|
||||
// Le chargement et le rendu de l'image se font dans un thread afin d'éviter le lag..
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
@ -72,6 +77,7 @@ public class Rendu extends MapRenderer implements Runnable
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
hasFail = true;
|
||||
}
|
||||
}
|
||||
if (touhou == null && local == true)
|
||||
@ -83,6 +89,7 @@ public class Rendu extends MapRenderer implements Runnable
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
hasFail = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,14 +98,19 @@ public class Rendu extends MapRenderer implements Runnable
|
||||
{
|
||||
try
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
File outputfile = new File("./plugins/ImageOnMap/map" + carte.getId() + ".png");
|
||||
File outputfile = new File("./plugins/ImageOnMap/Image/map" + carte.getId() + ".png");
|
||||
ImageIO.write(MapPalette.resizeImage(touhou), "png", outputfile);
|
||||
hasFail = false;
|
||||
} catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
hasFail = true;
|
||||
}
|
||||
}
|
||||
if(!hasFail && local == false)
|
||||
{
|
||||
SvgMap(carte.getId(), "map" + carte.getId(), joueur.getName());
|
||||
}
|
||||
|
||||
//System.out.println("Rendu de l'image..");
|
||||
|
||||
@ -115,6 +127,17 @@ public class Rendu extends MapRenderer implements Runnable
|
||||
|
||||
}
|
||||
|
||||
void SvgMap(int IdMap, String nomImage, String nomJoueur)
|
||||
{
|
||||
System.out.println("Sauvegarde de la map..");
|
||||
ArrayList<String> liste = new ArrayList<String>();
|
||||
liste.add(String.valueOf(IdMap));
|
||||
liste.add(nomImage);
|
||||
liste.add(nomJoueur);
|
||||
plugin.getConfig().set("map" + IdMap, liste);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
static void SupprRendu(MapView map)
|
||||
{
|
||||
if (map.getRenderers().size() != 0)
|
||||
|
Loading…
Reference in New Issue
Block a user