mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-01-10 09:48:02 +01:00
Ajout de la commande getmap; Ajout fichier config pour les maps
This commit is contained in:
parent
f967564107
commit
17d6813f3e
70
src/fr/moribus/ImageOnMap/GetMapCommand.java
Normal file
70
src/fr/moribus/ImageOnMap/GetMapCommand.java
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,8 +2,12 @@ package fr.moribus.ImageOnMap;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public final class ImageOnMap extends JavaPlugin
|
public final class ImageOnMap extends JavaPlugin
|
||||||
@ -11,6 +15,9 @@ public final class ImageOnMap extends JavaPlugin
|
|||||||
int test = 0;
|
int test = 0;
|
||||||
File dossier;
|
File dossier;
|
||||||
boolean dossierCree;
|
boolean dossierCree;
|
||||||
|
private FileConfiguration customConfig = null;
|
||||||
|
private File customConfigFile = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
@ -20,6 +27,9 @@ public final class ImageOnMap extends JavaPlugin
|
|||||||
// On ajoute si besoin les params par défaut du plugin
|
// On ajoute si besoin les params par défaut du plugin
|
||||||
ImgUtility.CreeSectionConfig(this);
|
ImgUtility.CreeSectionConfig(this);
|
||||||
|
|
||||||
|
if(getConfig().getBoolean("import-maps"))
|
||||||
|
ImgUtility.ImporterConfig(this);
|
||||||
|
|
||||||
if(this.getConfig().getBoolean("collect-data"))
|
if(this.getConfig().getBoolean("collect-data"))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -35,6 +45,7 @@ public final class ImageOnMap extends JavaPlugin
|
|||||||
if(dossierCree)
|
if(dossierCree)
|
||||||
{
|
{
|
||||||
getCommand("tomap").setExecutor(new ImageRenduCommande(this));
|
getCommand("tomap").setExecutor(new ImageRenduCommande(this));
|
||||||
|
getCommand("getmap").setExecutor(new GetMapCommand(this));
|
||||||
//getCommand("rmmap").setExecutor(new ImageSupprCommande(this));
|
//getCommand("rmmap").setExecutor(new ImageSupprCommande(this));
|
||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
ChargerMap();
|
ChargerMap();
|
||||||
@ -44,6 +55,7 @@ public final class ImageOnMap extends JavaPlugin
|
|||||||
System.out.println("[ImageOnMap] An error occured ! Unable to create Image folder. Plugin will NOT work !");
|
System.out.println("[ImageOnMap] An error occured ! Unable to create Image folder. Plugin will NOT work !");
|
||||||
this.setEnabled(false);
|
this.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -54,13 +66,13 @@ public final class ImageOnMap extends JavaPlugin
|
|||||||
|
|
||||||
public void ChargerMap()
|
public void ChargerMap()
|
||||||
{
|
{
|
||||||
Set<String> cle = getConfig().getKeys(false);
|
Set<String> cle = getCustomConfig().getKeys(false);
|
||||||
int nbMap = 0, nbErr = 0;
|
int nbMap = 0, nbErr = 0;
|
||||||
for (String s: cle)
|
for (String s: cle)
|
||||||
{
|
{
|
||||||
if(getConfig().getStringList(s).size() >= 3)
|
if(getCustomConfig().getStringList(s).size() >= 3)
|
||||||
{
|
{
|
||||||
SavedMap map = new SavedMap(this, Short.valueOf(getConfig().getStringList(s).get(0)));
|
SavedMap map = new SavedMap(this, Short.valueOf(getCustomConfig().getStringList(s).get(0)));
|
||||||
|
|
||||||
if(map.LoadMap())
|
if(map.LoadMap())
|
||||||
nbMap++;
|
nbMap++;
|
||||||
@ -74,4 +86,42 @@ public final class ImageOnMap extends JavaPlugin
|
|||||||
System.out.println(nbErr +" maps can't be loaded");
|
System.out.println(nbErr +" maps can't be loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reloadCustomConfig()
|
||||||
|
{
|
||||||
|
if (customConfigFile == null)
|
||||||
|
{
|
||||||
|
customConfigFile = new File(getDataFolder(), "map.yml");
|
||||||
|
}
|
||||||
|
customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
|
||||||
|
|
||||||
|
// Look for defaults in the jar
|
||||||
|
InputStream defConfigStream = this.getResource("map.yml");
|
||||||
|
if (defConfigStream != null)
|
||||||
|
{
|
||||||
|
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
|
||||||
|
customConfig.setDefaults(defConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfiguration getCustomConfig()
|
||||||
|
{
|
||||||
|
if (customConfig == null)
|
||||||
|
{
|
||||||
|
reloadCustomConfig();
|
||||||
|
}
|
||||||
|
return customConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveCustomConfig()
|
||||||
|
{
|
||||||
|
if (customConfig == null || customConfigFile == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
getCustomConfig().save(customConfigFile);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
getLogger().log(Level.SEVERE, "Could not save config to " + customConfigFile, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.moribus.ImageOnMap;
|
package fr.moribus.ImageOnMap;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -48,6 +49,8 @@ public class ImgUtility
|
|||||||
plugin.getConfig().set("Limit-map-by-player", 0);
|
plugin.getConfig().set("Limit-map-by-player", 0);
|
||||||
if(plugin.getConfig().get("collect-data") == null)
|
if(plugin.getConfig().get("collect-data") == null)
|
||||||
plugin.getConfig().set("collect-data", true);
|
plugin.getConfig().set("collect-data", true);
|
||||||
|
if(plugin.getConfig().get("import-maps") == null)
|
||||||
|
plugin.getConfig().set("import-maps", true);
|
||||||
plugin.saveConfig();
|
plugin.saveConfig();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -55,10 +58,10 @@ public class ImgUtility
|
|||||||
static int getNombreDeMaps(ImageOnMap plugin)
|
static int getNombreDeMaps(ImageOnMap plugin)
|
||||||
{
|
{
|
||||||
int nombre = 0;
|
int nombre = 0;
|
||||||
Set<String> cle = plugin.getConfig().getKeys(false);
|
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
||||||
for (String s: cle)
|
for (String s: cle)
|
||||||
{
|
{
|
||||||
if(plugin.getConfig().getStringList(s).size() >= 3)
|
if(plugin.getCustomConfig().getStringList(s).size() >= 3)
|
||||||
{
|
{
|
||||||
nombre++;
|
nombre++;
|
||||||
}
|
}
|
||||||
@ -69,10 +72,10 @@ public class ImgUtility
|
|||||||
static int getNombreDeMapsParJoueur(ImageOnMap plugin, String pseudo)
|
static int getNombreDeMapsParJoueur(ImageOnMap plugin, String pseudo)
|
||||||
{
|
{
|
||||||
int nombre = 0;
|
int nombre = 0;
|
||||||
Set<String> cle = plugin.getConfig().getKeys(false);
|
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
||||||
for (String s: cle)
|
for (String s: cle)
|
||||||
{
|
{
|
||||||
if(plugin.getConfig().getStringList(s).size() >= 3 && plugin.getConfig().getStringList(s).get(2).contentEquals(pseudo))
|
if(plugin.getCustomConfig().getStringList(s).size() >= 3 && plugin.getCustomConfig().getStringList(s).get(2).contentEquals(pseudo))
|
||||||
{
|
{
|
||||||
nombre++;
|
nombre++;
|
||||||
}
|
}
|
||||||
@ -82,10 +85,10 @@ public class ImgUtility
|
|||||||
|
|
||||||
static boolean EstDansFichier(ImageOnMap plugin, short id)
|
static boolean EstDansFichier(ImageOnMap plugin, short id)
|
||||||
{
|
{
|
||||||
Set<String> cle = plugin.getConfig().getKeys(false);
|
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
||||||
for (String s: cle)
|
for (String s: cle)
|
||||||
{
|
{
|
||||||
if(plugin.getConfig().getStringList(s).size() >= 3 && Short.parseShort(plugin.getConfig().getStringList(s).get(0)) == id)
|
if(plugin.getCustomConfig().getStringList(s).size() >= 3 && Short.parseShort(plugin.getCustomConfig().getStringList(s).get(0)) == id)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -95,14 +98,42 @@ public class ImgUtility
|
|||||||
|
|
||||||
public static boolean EstDansFichier(ImageOnMap plugin, short id, String pseudo)
|
public static boolean EstDansFichier(ImageOnMap plugin, short id, String pseudo)
|
||||||
{
|
{
|
||||||
Set<String> cle = plugin.getConfig().getKeys(false);
|
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
||||||
for (String s: cle)
|
for (String s: cle)
|
||||||
{
|
{
|
||||||
if(plugin.getConfig().getStringList(s).size() >= 3 && Short.parseShort(plugin.getConfig().getStringList(s).get(0)) == id && plugin.getConfig().getStringList(s).get(2).contentEquals(pseudo))
|
if(plugin.getCustomConfig().getStringList(s).size() >= 3 && Short.parseShort(plugin.getCustomConfig().getStringList(s).get(0)) == id && plugin.getCustomConfig().getStringList(s).get(2).contentEquals(pseudo))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean ImporterConfig(ImageOnMap plugin)
|
||||||
|
{
|
||||||
|
Set<String> cle = plugin.getConfig().getKeys(false);
|
||||||
|
|
||||||
|
plugin.getLogger().info("Start importing maps config to maps.yml...");
|
||||||
|
int i = 0;
|
||||||
|
for (String s: cle)
|
||||||
|
{
|
||||||
|
if(plugin.getConfig().getStringList(s).size() >= 3)
|
||||||
|
{
|
||||||
|
//plugin.getLogger().info("Importing "+ plugin.getConfig().getStringList(s).get(1));
|
||||||
|
ArrayList<String> liste = new ArrayList<String>();
|
||||||
|
liste.add(String.valueOf(plugin.getConfig().getStringList(s).get(0)));
|
||||||
|
liste.add(plugin.getConfig().getStringList(s).get(1));
|
||||||
|
liste.add(plugin.getConfig().getStringList(s).get(2));
|
||||||
|
plugin.getCustomConfig().set(plugin.getConfig().getStringList(s).get(1), liste);
|
||||||
|
plugin.getConfig().set(s, null);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
plugin.getLogger().info("Importing finished. "+ i+ "maps were imported");
|
||||||
|
plugin.getConfig().set("import-maps", false);
|
||||||
|
plugin.saveConfig();
|
||||||
|
plugin.saveCustomConfig();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
@ -32,17 +32,17 @@ public class SavedMap
|
|||||||
{
|
{
|
||||||
idMap = id;
|
idMap = id;
|
||||||
plugin = plug;
|
plugin = plug;
|
||||||
Set<String> cle = plugin.getConfig().getKeys(false);
|
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
||||||
int tmp = 0;
|
int tmp = 0;
|
||||||
for (String s: cle)
|
for (String s: cle)
|
||||||
{
|
{
|
||||||
if(plugin.getConfig().getStringList(s).size() >= 3 && Short.valueOf(plugin.getConfig().getStringList(s).get(0)) == id)
|
if(plugin.getCustomConfig().getStringList(s).size() >= 3 && Short.valueOf(plugin.getCustomConfig().getStringList(s).get(0)) == id)
|
||||||
{
|
{
|
||||||
tmp++;
|
tmp++;
|
||||||
//System.out.println(tmp);
|
//System.out.println(tmp);
|
||||||
//MapView carte = Bukkit.getMap(Short.parseShort(plugin.getConfig().getStringList(s).get(0)));
|
//MapView carte = Bukkit.getMap(Short.parseShort(plugin.getConfig().getStringList(s).get(0)));
|
||||||
nomImg = plugin.getConfig().getStringList(s).get(1);
|
nomImg = plugin.getCustomConfig().getStringList(s).get(1);
|
||||||
nomJoueur = plugin.getConfig().getStringList(s).get(2);
|
nomJoueur = plugin.getCustomConfig().getStringList(s).get(2);
|
||||||
try {
|
try {
|
||||||
image = ImageIO.read(new File("./plugins/ImageOnMap/Image/"+ nomImg + ".png"));
|
image = ImageIO.read(new File("./plugins/ImageOnMap/Image/"+ nomImg + ".png"));
|
||||||
//System.out.println("Chargement de l'image fini");
|
//System.out.println("Chargement de l'image fini");
|
||||||
@ -76,8 +76,8 @@ public class SavedMap
|
|||||||
liste.add(String.valueOf(idMap));
|
liste.add(String.valueOf(idMap));
|
||||||
liste.add(nomImg);
|
liste.add(nomImg);
|
||||||
liste.add(nomJoueur);
|
liste.add(nomJoueur);
|
||||||
plugin.getConfig().set(nomImg, liste);
|
plugin.getCustomConfig().set(nomImg, liste);
|
||||||
plugin.saveConfig();
|
plugin.saveCustomConfig();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user