mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-02-15 02:51:20 +01:00
Ajout de la commande tout-en-un maptool pour gérer les maps
This commit is contained in:
parent
17d6813f3e
commit
939b01f995
@ -1,13 +1,13 @@
|
||||
name: ImageOnMap
|
||||
main: fr.moribus.ImageOnMap.ImageOnMap
|
||||
version: 1.2.2
|
||||
version: 2.5.1
|
||||
|
||||
commands:
|
||||
tomap:
|
||||
description: render an image in a map
|
||||
usage: /<command> [URL]
|
||||
rmmap:
|
||||
description: remove an image
|
||||
maptool:
|
||||
description: manage maps
|
||||
usage: /<command>
|
||||
|
||||
permissions:
|
||||
|
@ -1,70 +0,0 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
public class GetMapCommand implements CommandExecutor
|
||||
{
|
||||
short id;
|
||||
ImageOnMap plugin;
|
||||
MapView map;
|
||||
Player joueur;
|
||||
Inventory inv;
|
||||
|
||||
GetMapCommand(ImageOnMap p)
|
||||
{
|
||||
plugin = p;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String arg2, String[] arg3)
|
||||
{
|
||||
|
||||
if(!ImgUtility.VerifierIdentite(sender))
|
||||
return false;
|
||||
|
||||
joueur = (Player) sender;
|
||||
inv = (Inventory) joueur.getInventory();
|
||||
|
||||
try
|
||||
{
|
||||
id = Short.parseShort(arg3[0]);
|
||||
}
|
||||
catch(NumberFormatException err)
|
||||
{
|
||||
joueur.sendMessage("you must enter a number !");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ImgUtility.EstDansFichier(plugin, id))
|
||||
{
|
||||
joueur.sendMessage("The given id does not match any map !");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(inv.firstEmpty() == -1)
|
||||
{
|
||||
joueur.sendMessage("Your inventory is full, you can't take the map !");
|
||||
return false;
|
||||
}
|
||||
|
||||
map = Bukkit.getMap(id);
|
||||
if(map == null)
|
||||
joueur.sendMessage("An eroor occured while getting map by ID !");
|
||||
|
||||
inv.addItem(new ItemStack(Material.MAP, 1, map.getId()));
|
||||
joueur.sendMessage("Map "+ ChatColor.ITALIC+ id+ ChatColor.RESET+ " was added in your inventory.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -45,8 +45,7 @@ public final class ImageOnMap extends JavaPlugin
|
||||
if(dossierCree)
|
||||
{
|
||||
getCommand("tomap").setExecutor(new ImageRenduCommande(this));
|
||||
getCommand("getmap").setExecutor(new GetMapCommand(this));
|
||||
//getCommand("rmmap").setExecutor(new ImageSupprCommande(this));
|
||||
getCommand("maptool").setExecutor(new MapToolCommand(this));
|
||||
this.saveDefaultConfig();
|
||||
ChargerMap();
|
||||
}
|
||||
@ -86,6 +85,10 @@ public final class ImageOnMap extends JavaPlugin
|
||||
System.out.println(nbErr +" maps can't be loaded");
|
||||
}
|
||||
|
||||
/* Méthodes pour charger / recharger / sauvegarder
|
||||
* le fichier conf des maps (map.yml).
|
||||
* Je les ai juste copié depuis un tuto du wiki Bukkit...
|
||||
*/
|
||||
public void reloadCustomConfig()
|
||||
{
|
||||
if (customConfigFile == null)
|
||||
|
@ -1,70 +0,0 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.map.MapView;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ImageSupprCommande implements CommandExecutor
|
||||
{
|
||||
|
||||
Plugin plugin;
|
||||
Player joueur;
|
||||
MapView carte;
|
||||
|
||||
public ImageSupprCommande(Plugin p)
|
||||
{
|
||||
plugin = p;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean onCommand(CommandSender arg0, Command arg1, String arg2,
|
||||
String[] arg3)
|
||||
{
|
||||
if (!ImgUtility.VerifierIdentite(arg0))
|
||||
return false;
|
||||
joueur = (Player) arg0;
|
||||
|
||||
if(!joueur.hasPermission("imageonmap.usermmap"))
|
||||
{
|
||||
joueur.sendMessage("You are not allowed to use this command ( " + arg1.getName() + " )!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(joueur.getItemInHand().getType() != Material.MAP)
|
||||
{
|
||||
joueur.sendMessage(ChatColor.RED + "you're not holding a map !");
|
||||
return false;
|
||||
}
|
||||
|
||||
carte = Bukkit.getMap(joueur.getItemInHand().getDurability());
|
||||
|
||||
Set<String> cle = plugin.getConfig().getKeys(false);
|
||||
for (String s: cle)
|
||||
{
|
||||
if(plugin.getConfig().getStringList(s).size() >= 3)
|
||||
{
|
||||
if(carte.getId() == Short.parseShort(plugin.getConfig().getStringList(s).get(0)))
|
||||
{
|
||||
ImageRenderer.SupprRendu(carte);
|
||||
plugin.getConfig().set(s, null);
|
||||
plugin.saveConfig();
|
||||
new File("./plugins/ImageOnMap/" + s + ".png").delete();
|
||||
joueur.sendMessage("The picture have been deleted");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -4,11 +4,13 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
public class ImgUtility
|
||||
{
|
||||
@ -136,4 +138,94 @@ public class ImgUtility
|
||||
plugin.saveCustomConfig();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fait la même chose que EstDansFichier() mais en retournant un objet MapView
|
||||
@SuppressWarnings("deprecation")
|
||||
static MapView getMap(ImageOnMap plugin, short id)
|
||||
{
|
||||
MapView map;
|
||||
if(!ImgUtility.EstDansFichier(plugin, id))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
map = Bukkit.getMap(id);
|
||||
if(map == null)
|
||||
{
|
||||
plugin.getLogger().warning("Map#"+ id+ " exists in maps.yml but not in the world folder !");
|
||||
return null;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
static boolean RemoveMap(ImageOnMap plugin, short id)
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
MapView carte = Bukkit.getMap(id);
|
||||
|
||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
||||
plugin.getLogger().info("POINT 2");
|
||||
for (String s: cle)
|
||||
{
|
||||
if(plugin.getCustomConfig().getStringList(s).size() >= 3)
|
||||
{
|
||||
if(carte == null && id == Short.parseShort(plugin.getCustomConfig().getStringList(s).get(0)))
|
||||
{
|
||||
//joueur.sendMessage("Suppression de la map dans fichier conf");
|
||||
plugin.getCustomConfig().set(s, null);
|
||||
plugin.saveCustomConfig();
|
||||
File map = new File("./plugins/ImageOnMap/Image/" + s + ".png");
|
||||
boolean isDeleted = map.delete();
|
||||
//joueur.sendMessage("The picture have been deleted");
|
||||
|
||||
if(isDeleted)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
plugin.getLogger().warning("Picture "+ s+ ".png cannot be deleted !");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
plugin.getCustomConfig().set(s, null);
|
||||
plugin.saveCustomConfig();
|
||||
File map = new File("./plugins/ImageOnMap/Image/" + s + ".png");
|
||||
boolean isDeleted = map.delete();
|
||||
//joueur.sendMessage("DEBUG: booléen isDeleted :"+ isDeleted+ "; Nom de la map : "+ plugin.getServer().getWorlds().get(0).getName());
|
||||
//joueur.sendMessage("The map has been deleted");
|
||||
if(isDeleted)
|
||||
return true;
|
||||
else
|
||||
{
|
||||
plugin.getLogger().warning("Picture "+ s+ ".png cannot be deleted !");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugin.getLogger().info("No map with id"+ id+ " was found");
|
||||
return false;
|
||||
}
|
||||
|
||||
static ArrayList<String> getListMapByPlayer(ImageOnMap plugin, String pseudo)
|
||||
{
|
||||
ArrayList<String> listeMap = new ArrayList<String>();
|
||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
||||
for (String s: cle)
|
||||
{
|
||||
if(plugin.getCustomConfig().getStringList(s).size() >= 3 && pseudo.equalsIgnoreCase(plugin.getCustomConfig().getStringList(s).get(2)))
|
||||
{
|
||||
listeMap.add(plugin.getCustomConfig().getStringList(s).get(0));
|
||||
}
|
||||
}
|
||||
return listeMap;
|
||||
}
|
||||
}
|
136
src/fr/moribus/ImageOnMap/MapToolCommand.java
Normal file
136
src/fr/moribus/ImageOnMap/MapToolCommand.java
Normal file
@ -0,0 +1,136 @@
|
||||
package fr.moribus.ImageOnMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
public class MapToolCommand implements CommandExecutor
|
||||
{
|
||||
short id;
|
||||
ImageOnMap plugin;
|
||||
MapView map;
|
||||
Player joueur;
|
||||
Inventory inv;
|
||||
|
||||
MapToolCommand(ImageOnMap p)
|
||||
{
|
||||
plugin = p;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String arg2, String[] arg3)
|
||||
{
|
||||
|
||||
if(!ImgUtility.VerifierIdentite(sender))
|
||||
return false;
|
||||
|
||||
String nomCmd = arg2;
|
||||
joueur = (Player) sender;
|
||||
inv = (Inventory) joueur.getInventory();
|
||||
|
||||
if(arg3.length < 1)
|
||||
{
|
||||
joueur.sendMessage("Map tools usage:" +
|
||||
"\n/"+ ChatColor.GOLD + nomCmd+ ChatColor.RESET+ " get [id]: get the map corresponding to this id" +
|
||||
"\n/"+ ChatColor.GOLD + nomCmd+ ChatColor.RESET+ " delete [id]: remove the map corresponding to this id" +
|
||||
"\n/"+ ChatColor.GOLD + nomCmd+ ChatColor.RESET+ " list: show all ids of maps in your possession");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(arg3[0].equalsIgnoreCase("get"))
|
||||
{
|
||||
try
|
||||
{
|
||||
id = Short.parseShort(arg3[1]);
|
||||
}
|
||||
catch(NumberFormatException err)
|
||||
{
|
||||
joueur.sendMessage("you must enter a number !");
|
||||
return true;
|
||||
}
|
||||
|
||||
map = ImgUtility.getMap(plugin, id);
|
||||
|
||||
if(map == null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if(inv.firstEmpty() == -1)
|
||||
{
|
||||
joueur.sendMessage("Your inventory is full, you can't take the map !");
|
||||
return true;
|
||||
}
|
||||
|
||||
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.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
else if(arg3[0].equalsIgnoreCase("delete"))
|
||||
{
|
||||
if(!joueur.hasPermission("imageonmap.usermmap"))
|
||||
{
|
||||
joueur.sendMessage("You are not allowed to delete map !");
|
||||
return true;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
id = Short.parseShort(arg3[1]);
|
||||
}
|
||||
catch(NumberFormatException err)
|
||||
{
|
||||
joueur.sendMessage("you must enter a number !");
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean success = ImgUtility.RemoveMap(plugin, id);
|
||||
|
||||
if(success)
|
||||
{
|
||||
joueur.sendMessage("Map#"+ id+ " was deleted");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
joueur.sendMessage(ChatColor.RED+ "Can't delete delete Map#"+ id+ ": check the server log");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
else if(arg3[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
String msg = "";
|
||||
int compteur = 0;
|
||||
ArrayList<String> liste = new ArrayList<String>();
|
||||
|
||||
liste = ImgUtility.getListMapByPlayer(plugin, joueur.getName());
|
||||
|
||||
for (; compteur < liste.size(); compteur++)
|
||||
{
|
||||
msg += liste.get(compteur)+ " ";
|
||||
}
|
||||
joueur.sendMessage(msg+
|
||||
"\nYou have rendered "+ ChatColor.DARK_PURPLE+ (compteur + 1)+ ChatColor.RESET+ " pictures");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -73,6 +73,7 @@ public class TacheTraitementMap extends BukkitRunnable
|
||||
//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");
|
||||
}
|
||||
|
6
todo.txt
Normal file
6
todo.txt
Normal file
@ -0,0 +1,6 @@
|
||||
- Créer un fichier config dédié à l'enregistrement des maps = FAIT !
|
||||
- Stocker les maps dans un coffre s'il n'y a plus de place dans l'inventaire du joueur
|
||||
- Pouvoir charger une image locale
|
||||
- Ajouter une option permettant de redimensioner une image
|
||||
- IMPORTANT: sauvegarder les images selon la map
|
||||
- IMPORTANT (mais difficilement faisable pour le moment): enregistrer les maps dans leurs fichiers "natifs" (dans le dossier de la map)
|
Loading…
Reference in New Issue
Block a user