mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-09-24 20:53:07 +02:00
Started refactoring. Plugin is not working yet !
* NEW: Added proper license headers. * NEW: New image loading management. * NEW: Added a threaded worker to run the image loading/saving. * OPT: Moved images to the images/ subdirectory.
This commit is contained in:
parent
bdf35e9eef
commit
1cb42e4965
21
licenseheader.txt
Normal file
21
licenseheader.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<#if licenseFirst??>
|
||||||
|
${licenseFirst}
|
||||||
|
</#if>
|
||||||
|
${licensePrefix}Copyright (C) 2013 Moribus
|
||||||
|
${licensePrefix}Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
${licensePrefix?replace(" +$", "", "r")}
|
||||||
|
${licensePrefix}This program is free software: you can redistribute it and/or modify
|
||||||
|
${licensePrefix}it under the terms of the GNU General Public License as published by
|
||||||
|
${licensePrefix}the Free Software Foundation, either version 3 of the License, or
|
||||||
|
${licensePrefix}(at your option) any later version.
|
||||||
|
${licensePrefix?replace(" +$", "", "r")}
|
||||||
|
${licensePrefix}This program is distributed in the hope that it will be useful,
|
||||||
|
${licensePrefix}but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
${licensePrefix}MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
${licensePrefix}GNU General Public License for more details.
|
||||||
|
${licensePrefix?replace(" +$", "", "r")}
|
||||||
|
${licensePrefix}You should have received a copy of the GNU General Public License
|
||||||
|
${licensePrefix}along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
<#if licenseLast??>
|
||||||
|
${licenseLast}
|
||||||
|
</#if>
|
18
nb-configuration.xml
Normal file
18
nb-configuration.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<netbeans.hint.licensePath>${project.basedir}/licenseheader.txt</netbeans.hint.licensePath>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
@ -1,30 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package fr.moribus.imageonmap;
|
package fr.moribus.imageonmap;
|
||||||
|
|
||||||
import fr.moribus.imageonmap.commands.MapToolCommand;
|
import fr.moribus.imageonmap.image.ImageIOExecutor;
|
||||||
import fr.moribus.imageonmap.commands.ImageRenduCommande;
|
import fr.moribus.imageonmap.image.MapInitEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap;
|
|
||||||
import fr.moribus.imageonmap.map.SingleMap;
|
|
||||||
|
|
||||||
public final class ImageOnMap extends JavaPlugin
|
public final class ImageOnMap extends JavaPlugin
|
||||||
{
|
{
|
||||||
|
static private final String IMAGES_DIRECTORY_NAME = "images";
|
||||||
static private ImageOnMap plugin;
|
static private ImageOnMap plugin;
|
||||||
|
|
||||||
|
private final File imagesDirectory;
|
||||||
|
|
||||||
public ImageOnMap()
|
public ImageOnMap()
|
||||||
{
|
{
|
||||||
|
imagesDirectory = new File(this.getDataFolder(), IMAGES_DIRECTORY_NAME);
|
||||||
plugin = this;
|
plugin = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,169 +41,35 @@ public final class ImageOnMap extends JavaPlugin
|
|||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean dossierCree;
|
public File getImagesDirectory() {return imagesDirectory;}
|
||||||
private FileConfiguration customConfig = null;
|
public File getImageFile(short mapID)
|
||||||
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
|
return new File(imagesDirectory, "map"+mapID+".png");
|
||||||
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
|
@Override
|
||||||
public void onEnable()
|
public void onEnable()
|
||||||
{
|
{
|
||||||
// On crée si besoin le dossier où les images seront stockées
|
// Creating the images directory if necessary
|
||||||
dossierCree = ImgUtility.CreeRepImg(this);
|
if(!imagesDirectory.exists())
|
||||||
|
|
||||||
// On ajoute si besoin les params par défaut du plugin
|
|
||||||
ImgUtility.CreeSectionConfig(this);
|
|
||||||
if (getConfig().get("map_path") == null)
|
|
||||||
{
|
{
|
||||||
getConfig().set("map_path", getServer().getWorlds().get(0).getName());
|
if(!imagesDirectory.mkdirs())
|
||||||
}
|
|
||||||
else if (getConfig().get("map_path") != getServer().getWorlds().get(0).getName())
|
|
||||||
{
|
{
|
||||||
getConfig().set("map_path", getServer().getWorlds().get(0).getName());
|
PluginLogger.LogError("FATAL : Could not create the images directory.", null);
|
||||||
}
|
|
||||||
|
|
||||||
if (getConfig().getBoolean("import-maps"))
|
|
||||||
{
|
|
||||||
ImgUtility.ImporterConfig(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getConfig().getBoolean("collect-data"))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
MetricsLite metrics = new MetricsLite(this);
|
|
||||||
metrics.start();
|
|
||||||
getLogger().info("Metrics launched for ImageOnMap");
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
PluginLogger.LogError("Failed to start Plugin metrics", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dossierCree)
|
|
||||||
{
|
|
||||||
getCommand("tomap").setExecutor(new ImageRenduCommande(this));
|
|
||||||
getCommand("maptool").setExecutor(new MapToolCommand(this));
|
|
||||||
getServer().getPluginManager().registerEvents(new SendMapOnFrameEvent(this), this);
|
|
||||||
getServer().getPluginManager().registerEvents(new SendMapOnInvEvent(this), this);
|
|
||||||
this.saveDefaultConfig();
|
|
||||||
//ChargerMap();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
getLogger().info("[ImageOnMap] An error occured ! Unable to create Image folder. Plugin will NOT work !");
|
|
||||||
this.setEnabled(false);
|
this.setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MetricsLite.startMetrics();
|
||||||
|
ImageIOExecutor.start();
|
||||||
|
getServer().getPluginManager().registerEvents(new MapInitEvent(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
getLogger().info("Stopping ImageOnMap");
|
ImageIOExecutor.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChargerMap()
|
|
||||||
{
|
|
||||||
Set<String> cle = getCustomConfig().getKeys(false);
|
|
||||||
int nbMap = 0, nbErr = 0;
|
|
||||||
for (String s : cle)
|
|
||||||
{
|
|
||||||
if (getCustomConfig().getStringList(s).size() >= 3)
|
|
||||||
{
|
|
||||||
ImageMap map;
|
|
||||||
String stringID = getCustomConfig().getStringList(s).get(0);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
map = new SingleMap(Short.valueOf(stringID));
|
|
||||||
|
|
||||||
map.load();
|
|
||||||
nbMap++;
|
|
||||||
}
|
|
||||||
catch (NumberFormatException e)
|
|
||||||
{
|
|
||||||
PluginLogger.LogWarning("Could not parse map ID from config", e);
|
|
||||||
nbErr++;
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
PluginLogger.LogError("Could not load map ID " + stringID, e);
|
|
||||||
nbErr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
PluginLogger.LogInfo(nbMap + " maps successfuly loaded.");
|
|
||||||
if (nbErr != 0)
|
|
||||||
PluginLogger.LogWarning(nbErr + " couldn'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.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<ItemStack> getRemainingMaps(String j)
|
|
||||||
{
|
|
||||||
return cache.get(j);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemainingMaps(String j, ArrayList<ItemStack> remaining)
|
|
||||||
{
|
|
||||||
cache.put(j, remaining);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeRemaingMaps(String j)
|
|
||||||
{
|
|
||||||
cache.remove(j);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,266 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
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.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.map.MapView;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.map.SingleMap;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
public class ImgUtility
|
|
||||||
{
|
|
||||||
|
|
||||||
// Vérifie que c'est bien un joueur qui exécute la commande
|
|
||||||
static public boolean VerifierIdentite(CommandSender sender)
|
|
||||||
{
|
|
||||||
if (sender instanceof Player)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (sender instanceof ConsoleCommandSender)
|
|
||||||
{System.out.println(ChatColor.RED + "Cette commande ne peut être utilisée dans la console !"); return false;}
|
|
||||||
else if (sender instanceof BlockCommandSender)
|
|
||||||
{System.out.println(ChatColor.RED + "Cette commande ne peut être utilisée par un bloc-commande !"); return false;}
|
|
||||||
else
|
|
||||||
{System.out.println(ChatColor.RED + "Cette commande ne peut être lancée de cette façon !"); return false;}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creation du dossier où sera stocké les images
|
|
||||||
static public boolean CreeRepImg(ImageOnMap plugin)
|
|
||||||
{
|
|
||||||
File dossier;
|
|
||||||
dossier = new File(plugin.getDataFolder().getPath() + "/Image");
|
|
||||||
if (!dossier.exists())
|
|
||||||
{
|
|
||||||
return dossier.mkdirs();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void CreeSectionConfig(ImageOnMap plugin)
|
|
||||||
{
|
|
||||||
if(plugin.getConfig().get("Limit-map-by-server") == null)
|
|
||||||
plugin.getConfig().set("Limit-map-by-server", 0);
|
|
||||||
if(plugin.getConfig().get("Limit-map-by-player") == null)
|
|
||||||
plugin.getConfig().set("Limit-map-by-player", 0);
|
|
||||||
if(plugin.getConfig().get("collect-data") == null)
|
|
||||||
plugin.getConfig().set("collect-data", true);
|
|
||||||
if(plugin.getConfig().get("import-maps") == null)
|
|
||||||
plugin.getConfig().set("import-maps", true);
|
|
||||||
if(plugin.getConfig().get("send-entire-maps") == null)
|
|
||||||
plugin.getConfig().set("send-entire-maps", 0);
|
|
||||||
plugin.saveConfig();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getNombreDeMaps(ImageOnMap plugin)
|
|
||||||
{
|
|
||||||
int nombre = 0;
|
|
||||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
|
||||||
for (String s: cle)
|
|
||||||
{
|
|
||||||
if(plugin.getCustomConfig().getStringList(s).size() >= 3)
|
|
||||||
{
|
|
||||||
nombre++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getNombreDeMapsParJoueur(ImageOnMap plugin, String pseudo)
|
|
||||||
{
|
|
||||||
int nombre = 0;
|
|
||||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
|
||||||
for (String s: cle)
|
|
||||||
{
|
|
||||||
if(plugin.getCustomConfig().getStringList(s).size() >= 3 && plugin.getCustomConfig().getStringList(s).get(2).contentEquals(pseudo))
|
|
||||||
{
|
|
||||||
nombre++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nombre;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean EstDansFichier(ImageOnMap plugin, short id)
|
|
||||||
{
|
|
||||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
|
||||||
for (String s: cle)
|
|
||||||
{
|
|
||||||
if(plugin.getCustomConfig().getStringList(s).size() >= 3 && Short.parseShort(plugin.getCustomConfig().getStringList(s).get(0)) == id)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean EstDansFichier(ImageOnMap plugin, short id, String pseudo)
|
|
||||||
{
|
|
||||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
|
||||||
for (String s: cle)
|
|
||||||
{
|
|
||||||
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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 public boolean RemoveMap(ImageOnMap plugin, short id)
|
|
||||||
{
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
MapView carte = Bukkit.getMap(id);
|
|
||||||
|
|
||||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
|
||||||
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");
|
|
||||||
SingleMap.SupprRendu(carte);
|
|
||||||
/*if(plugin.getConfig().get("delete") != null);
|
|
||||||
{
|
|
||||||
ArrayList<String> ListeSuppr = (ArrayList<String>) plugin.getConfig().getStringList("delete");
|
|
||||||
ListeSuppr.add(plugin.getCustomConfig().getStringList(s).get(0));
|
|
||||||
plugin.getConfig().set("delete", ListeSuppr);
|
|
||||||
}*/
|
|
||||||
plugin.getCustomConfig().set(s, null);
|
|
||||||
plugin.saveCustomConfig();
|
|
||||||
plugin.saveConfig();
|
|
||||||
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 public 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static public void AddMap(ItemStack map, Inventory inv, ArrayList<ItemStack> restant)
|
|
||||||
{
|
|
||||||
HashMap<Integer,ItemStack> reste = inv.addItem(map);
|
|
||||||
|
|
||||||
if(!reste.isEmpty())
|
|
||||||
{
|
|
||||||
restant.add(reste.get(0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BufferedImage scaleImage(Image image, int width, int height)
|
|
||||||
{
|
|
||||||
BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
|
||||||
Graphics2D g = newImage.createGraphics();
|
|
||||||
g.drawImage(image, 0, 0, width, height, null);
|
|
||||||
g.dispose();
|
|
||||||
return newImage;
|
|
||||||
}
|
|
||||||
}
|
|
@ -50,7 +50,25 @@ import java.util.UUID;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.zip.GZIPOutputStream;
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
public class MetricsLite {
|
public class MetricsLite
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Starts MetricsLite, unless disabled in config
|
||||||
|
*/
|
||||||
|
|
||||||
|
static public void startMetrics()
|
||||||
|
{
|
||||||
|
if(!PluginConfiguration.COLLECT_DATA.getBoolean()) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
MetricsLite metrics = new MetricsLite(ImageOnMap.getPlugin());
|
||||||
|
metrics.start();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
PluginLogger.LogError("Failed to start MetricsLite", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current revision number
|
* The current revision number
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
|
||||||
|
|
||||||
public class PlayerListener implements Listener
|
|
||||||
{
|
|
||||||
ImageOnMap plugin;
|
|
||||||
HashMap<String, SendEntireMapTask> hmap;
|
|
||||||
int send;
|
|
||||||
|
|
||||||
PlayerListener(ImageOnMap p)
|
|
||||||
{
|
|
||||||
plugin = p;
|
|
||||||
hmap = new HashMap<String, SendEntireMapTask>();
|
|
||||||
send = plugin.getConfig().getInt("send-entire-maps");
|
|
||||||
}
|
|
||||||
@EventHandler
|
|
||||||
public void OnPlayerLogin(PlayerLoginEvent event)
|
|
||||||
{
|
|
||||||
if(send > 0)
|
|
||||||
{
|
|
||||||
Player joueur = event.getPlayer();
|
|
||||||
hmap.put(joueur.getName(), new SendEntireMapTask(plugin, event.getPlayer()));
|
|
||||||
hmap.get(joueur.getName()).runTaskTimer(plugin, 40, 20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void OnPlayerLeft(PlayerQuitEvent event)
|
|
||||||
{
|
|
||||||
if(send > 0)
|
|
||||||
{
|
|
||||||
Player joueur = event.getPlayer();
|
|
||||||
hmap.get(joueur.getName()).cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
79
src/main/java/fr/moribus/imageonmap/PluginConfiguration.java
Normal file
79
src/main/java/fr/moribus/imageonmap/PluginConfiguration.java
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fr.moribus.imageonmap;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
public enum PluginConfiguration
|
||||||
|
{
|
||||||
|
//Configuration field Names, with default values
|
||||||
|
COLLECT_DATA("collect-data", true),
|
||||||
|
MAP_GLOBAL_LIMIT("map-global-limit", 0),
|
||||||
|
MAP_PLAYER_LIMIT("map-player-limit", 0);
|
||||||
|
|
||||||
|
private final String fieldName;
|
||||||
|
private final Object defaultValue;
|
||||||
|
|
||||||
|
private PluginConfiguration(String fieldName, Object defaultValue)
|
||||||
|
{
|
||||||
|
this.fieldName = fieldName;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object get()
|
||||||
|
{
|
||||||
|
return getConfig().get(fieldName, defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getDefaultValue()
|
||||||
|
{
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDefaultValue()
|
||||||
|
{
|
||||||
|
return get().equals(defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return get().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString()
|
||||||
|
{
|
||||||
|
return getConfig().getString(fieldName, (String)defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInteger()
|
||||||
|
{
|
||||||
|
return getConfig().getInt(fieldName, (Integer)defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBoolean()
|
||||||
|
{
|
||||||
|
return getConfig().getBoolean(fieldName, (Boolean)defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
static public FileConfiguration getConfig()
|
||||||
|
{
|
||||||
|
return ImageOnMap.getPlugin().getConfig();
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2014 ProkopyL
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* modify it under the terms of the GNU General Public License
|
* it under the terms of the GNU General Public License as published by
|
||||||
* as published by the Free Software Foundation; either version 2
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* of the License, or (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
@ -12,8 +13,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package fr.moribus.imageonmap;
|
package fr.moribus.imageonmap;
|
||||||
|
@ -1,107 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.image.Renderer;
|
|
||||||
import fr.moribus.imageonmap.image.ImageRendererThread;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.map.MapPalette;
|
|
||||||
import org.bukkit.map.MapView;
|
|
||||||
|
|
||||||
public class SavedMap
|
|
||||||
{
|
|
||||||
|
|
||||||
ImageOnMap plugin;
|
|
||||||
String nomImg, nomJoueur, nomMonde;
|
|
||||||
short idMap;
|
|
||||||
BufferedImage image;
|
|
||||||
boolean loaded = false;
|
|
||||||
|
|
||||||
SavedMap(ImageOnMap plug, String nomJ, short id, BufferedImage img, String nomM)
|
|
||||||
{
|
|
||||||
plugin = plug;
|
|
||||||
nomJoueur = nomJ;
|
|
||||||
idMap = id;
|
|
||||||
image = img;
|
|
||||||
nomImg = "map" + id;
|
|
||||||
nomMonde = nomM;
|
|
||||||
loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
SavedMap(ImageOnMap plug, short id) throws IOException
|
|
||||||
{
|
|
||||||
idMap = id;
|
|
||||||
plugin = plug;
|
|
||||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
|
||||||
for (String s : cle)
|
|
||||||
{
|
|
||||||
if (plugin.getCustomConfig().getStringList(s).size() >= 3 && Short.valueOf(plugin.getCustomConfig().getStringList(s).get(0)) == id)
|
|
||||||
{
|
|
||||||
//System.out.println(tmp);
|
|
||||||
//MapView carte = Bukkit.getMap(Short.parseShort(plugin.getConfig().getStringList(s).get(0)));
|
|
||||||
nomImg = plugin.getCustomConfig().getStringList(s).get(1);
|
|
||||||
nomJoueur = plugin.getCustomConfig().getStringList(s).get(2);
|
|
||||||
image = ImageIO.read(new File("./plugins/ImageOnMap/Image/" + nomImg + ".png"));
|
|
||||||
loaded = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!loaded)
|
|
||||||
{
|
|
||||||
//plugin.getLogger().info("No map was loaded");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveMap() throws IOException
|
|
||||||
{
|
|
||||||
if (!loaded)
|
|
||||||
{
|
|
||||||
PluginLogger.LogWarning("Tried to save a map that wasn't loaded. ID:" + idMap);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
plugin.getLogger().info("Saving map " + idMap);
|
|
||||||
|
|
||||||
// Enregistrement de l'image sur le disque dur
|
|
||||||
File outputfile = new File("./plugins/ImageOnMap/Image/" + nomImg + ".png");
|
|
||||||
ImageIO.write(MapPalette.resizeImage(image), "png", outputfile);
|
|
||||||
// Enregistrement de la map dans la config
|
|
||||||
ArrayList<String> liste = new ArrayList<String>();
|
|
||||||
liste.add(String.valueOf(idMap));
|
|
||||||
liste.add(nomImg);
|
|
||||||
liste.add(nomJoueur);
|
|
||||||
liste.add(nomMonde);
|
|
||||||
plugin.getCustomConfig().set(nomImg, liste);
|
|
||||||
plugin.saveCustomConfig();
|
|
||||||
if (!plugin.mapChargee.contains(idMap))
|
|
||||||
{
|
|
||||||
plugin.mapChargee.add(idMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public Boolean LoadMap()
|
|
||||||
{
|
|
||||||
MapView carte = Bukkit.getMap(idMap);
|
|
||||||
if (carte != null && loaded)
|
|
||||||
{
|
|
||||||
ImageRendererThread.SupprRendu(carte);
|
|
||||||
carte.addRenderer(new Renderer(image));
|
|
||||||
if (!plugin.mapChargee.contains(idMap))
|
|
||||||
{
|
|
||||||
plugin.mapChargee.add(idMap);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,155 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
|
|
||||||
public class SavedPoster
|
|
||||||
{
|
|
||||||
ImageOnMap plugin;
|
|
||||||
short[] ids;
|
|
||||||
private FileConfiguration customConfig = null;
|
|
||||||
private File customConfigFile = null;
|
|
||||||
String posterName, playerName;
|
|
||||||
|
|
||||||
public SavedPoster(ImageOnMap plugin, short[] ids, String playerName, String posterName)
|
|
||||||
{
|
|
||||||
this.ids = ids;
|
|
||||||
this.plugin = plugin;
|
|
||||||
this.playerName = playerName;
|
|
||||||
this.posterName = posterName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SavedPoster(ImageOnMap plugin, short[] ids, String playerName)
|
|
||||||
{
|
|
||||||
this(plugin, ids, playerName, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SavedPoster(ImageOnMap plugin)
|
|
||||||
{
|
|
||||||
this(plugin, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SavedPoster(ImageOnMap p, String id)
|
|
||||||
{
|
|
||||||
plugin = p;
|
|
||||||
posterName = id;
|
|
||||||
ArrayList<String> liste = (ArrayList<String>) getCustomConfig().getStringList(posterName);
|
|
||||||
if (!liste.isEmpty() || liste != null)
|
|
||||||
{
|
|
||||||
playerName = liste.get(0);
|
|
||||||
ids = new short[liste.size() - 1];
|
|
||||||
for (int i = 0; i < ids.length; i++)
|
|
||||||
{
|
|
||||||
ids[i] = Short.parseShort(liste.get(i + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String Save() throws IOException
|
|
||||||
{
|
|
||||||
int increment = increment();
|
|
||||||
ArrayList<String> liste = new ArrayList<String>();
|
|
||||||
liste.add(playerName);
|
|
||||||
for (int i = 0; i < ids.length; i++)
|
|
||||||
{
|
|
||||||
liste.add(String.valueOf(ids[i]));
|
|
||||||
}
|
|
||||||
posterName = "poster" + increment;
|
|
||||||
getCustomConfig().set(posterName, liste);
|
|
||||||
saveCustomConfig();
|
|
||||||
return posterName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Remove() throws IOException
|
|
||||||
{
|
|
||||||
if (posterName == null || posterName.isEmpty()) return;
|
|
||||||
for (int i = 0; i < ids.length; i++)
|
|
||||||
{
|
|
||||||
ImgUtility.RemoveMap(plugin, ids[i]);
|
|
||||||
}
|
|
||||||
getCustomConfig().set(posterName, null);
|
|
||||||
saveCustomConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
int increment()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
if (getCustomConfig().get("IdCount") != null)
|
|
||||||
{
|
|
||||||
i = getCustomConfig().getInt("IdCount");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
this.getCustomConfig().set("IdCount", i);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getId()
|
|
||||||
{
|
|
||||||
return posterName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getListMapByPlayer(ImageOnMap plugin, String pseudo)
|
|
||||||
{
|
|
||||||
ArrayList<String> listeMap = new ArrayList<String>();
|
|
||||||
Set<String> cle = getCustomConfig().getKeys(false);
|
|
||||||
for (String s : cle)
|
|
||||||
{
|
|
||||||
if (getCustomConfig().getStringList(s).size() > 1 && pseudo.equalsIgnoreCase(getCustomConfig().getStringList(s).get(0)))
|
|
||||||
{
|
|
||||||
listeMap.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return listeMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 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()
|
|
||||||
{
|
|
||||||
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() throws IOException
|
|
||||||
{
|
|
||||||
if (customConfig == null || customConfigFile == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getCustomConfig().save(customConfigFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,81 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.map.MapView;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public class SendEntireMapTask extends BukkitRunnable
|
|
||||||
{
|
|
||||||
ImageOnMap plugin;
|
|
||||||
Player joueur;
|
|
||||||
ArrayList<Short> listeMap;
|
|
||||||
List<Short> partListe;
|
|
||||||
boolean allsent;
|
|
||||||
int index, toIndex, nbSend;
|
|
||||||
|
|
||||||
SendEntireMapTask(ImageOnMap p, Player j)
|
|
||||||
{
|
|
||||||
plugin = p;
|
|
||||||
joueur = j;
|
|
||||||
allsent = false;
|
|
||||||
index = 0;
|
|
||||||
nbSend = plugin.getConfig().getInt("send-entire-maps");
|
|
||||||
toIndex = nbSend;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
if(nbSend > 0)
|
|
||||||
{
|
|
||||||
if(listeMap == null)
|
|
||||||
{
|
|
||||||
//plugin.getLogger().info("test de nullité");
|
|
||||||
listeMap = new ArrayList<Short>();
|
|
||||||
listeMap.addAll(plugin.mapChargee);
|
|
||||||
}
|
|
||||||
else if(listeMap.equals(plugin.mapChargee) != true)
|
|
||||||
{
|
|
||||||
//plugin.getLogger().info("taille des maps : " + listeMap.size()+ " ; "+ plugin.mapChargee.size());
|
|
||||||
//plugin.getLogger().info("test d'égalité");
|
|
||||||
listeMap.clear();
|
|
||||||
listeMap.addAll(plugin.mapChargee);
|
|
||||||
allsent = false;
|
|
||||||
}
|
|
||||||
if(!allsent)
|
|
||||||
{
|
|
||||||
//plugin.getLogger().info("test 1");
|
|
||||||
if(toIndex > listeMap.size())
|
|
||||||
{
|
|
||||||
//plugin.getLogger().info("test 3");
|
|
||||||
partListe = listeMap.subList(index, listeMap.size());
|
|
||||||
index = listeMap.size();
|
|
||||||
toIndex = listeMap.size() + nbSend;
|
|
||||||
allsent = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//plugin.getLogger().info("taille des index : " + index+ " ; "+ toIndex+ ". taille de la map : "
|
|
||||||
// + listeMap.size());
|
|
||||||
//plugin.getLogger().info("test 2");
|
|
||||||
partListe = listeMap.subList(index, toIndex);
|
|
||||||
index = toIndex;
|
|
||||||
toIndex += nbSend;
|
|
||||||
}
|
|
||||||
for(int i= 0; i< partListe.size(); i++)
|
|
||||||
{
|
|
||||||
//plugin.getLogger().info("test 4");
|
|
||||||
MapView map = Bukkit.getMap(partListe.get(i));
|
|
||||||
joueur.sendMap(map);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.bukkit.Chunk;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.ItemFrame;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
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;
|
|
||||||
Chunk chunk;
|
|
||||||
Entity[] entites;
|
|
||||||
ItemFrame frame;
|
|
||||||
|
|
||||||
SendMapOnFrameEvent(ImageOnMap plug)
|
|
||||||
{
|
|
||||||
plugin = plug;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onChunkLoad(ChunkLoadEvent event)
|
|
||||||
{
|
|
||||||
chunk = event.getChunk();
|
|
||||||
entites = chunk.getEntities().clone();
|
|
||||||
for (Entity entite : entites)
|
|
||||||
{
|
|
||||||
if (entite instanceof ItemFrame)
|
|
||||||
{
|
|
||||||
ArrayList<Short> ListeId = plugin.mapChargee;
|
|
||||||
frame = (ItemFrame) entite;
|
|
||||||
ItemStack stack = frame.getItem();
|
|
||||||
if (stack.getType() == Material.MAP && !ListeId.contains(stack.getDurability()))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
new SingleMap(stack.getDurability()).load();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
PluginLogger.LogWarning("Could not send frame map", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
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
|
|
||||||
{
|
|
||||||
ImageOnMap plugin;
|
|
||||||
|
|
||||||
SendMapOnInvEvent(ImageOnMap p)
|
|
||||||
{
|
|
||||||
plugin = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerInv(PlayerItemHeldEvent event)
|
|
||||||
{
|
|
||||||
Player joueur = event.getPlayer();
|
|
||||||
int slot = event.getNewSlot();
|
|
||||||
ItemStack stack = joueur.getInventory().getItem(slot);
|
|
||||||
|
|
||||||
if (stack != null && stack.getType() == Material.MAP)
|
|
||||||
{
|
|
||||||
|
|
||||||
ArrayList<Short> listeId = plugin.mapChargee;
|
|
||||||
Set<String> cle = plugin.getCustomConfig().getKeys(false);
|
|
||||||
for (String s : cle)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!listeId.contains(stack.getDurability()))
|
|
||||||
{
|
|
||||||
if (plugin.getCustomConfig().getStringList(s).get(0).equals(String.valueOf(stack.getDurability())))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
new SingleMap(stack.getDurability()).load();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
PluginLogger.LogWarning("Could not send inventory map.", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class TacheTraitementMajMap extends TacheTraitementMap
|
|
||||||
{
|
|
||||||
private ImageMap m;
|
|
||||||
|
|
||||||
public TacheTraitementMajMap(ImageMap m, URL url, Player joueur)
|
|
||||||
{
|
|
||||||
super(url);
|
|
||||||
setJoueur(joueur);
|
|
||||||
this.m = m;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void traiterMap(BufferedImage img) throws IOException
|
|
||||||
{
|
|
||||||
m.setImage(img);
|
|
||||||
m.save();
|
|
||||||
m.send(getJoueur());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,194 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.image.DownloadImageThread;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
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.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
|
|
||||||
public abstract class TacheTraitementMap extends BukkitRunnable
|
|
||||||
{
|
|
||||||
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(URL url)
|
|
||||||
{
|
|
||||||
renduImg = new DownloadImageThread(url);
|
|
||||||
dlImg = Executors.newSingleThreadExecutor();
|
|
||||||
futurDlImg = dlImg.submit(renduImg);
|
|
||||||
plugin = (ImageOnMap) Bukkit.getPluginManager().getPlugin("ImageOnMap");
|
|
||||||
}
|
|
||||||
|
|
||||||
public TacheTraitementMap(Player j, URL url, boolean rs, boolean rn)
|
|
||||||
{
|
|
||||||
this(url);
|
|
||||||
joueur = j;
|
|
||||||
inv = joueur.getInventory();
|
|
||||||
resized = rs;
|
|
||||||
renamed = rn;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
compteurExec = 0;
|
|
||||||
if (!futurDlImg.isDone())
|
|
||||||
{
|
|
||||||
compteurExec++;
|
|
||||||
if (compteurExec > 20)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("TIMEOUT: the render took too many time");
|
|
||||||
futurDlImg.cancel(true);
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
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"))
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
BufferedImage dlimg = futurDlImg.get();
|
|
||||||
traiterMap(dlimg);
|
|
||||||
joueur.sendMessage("Image successfuly downloaded !");
|
|
||||||
}
|
|
||||||
catch (InterruptedException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage(ChatColor.RED + "Download task has been interrupted unexpectedly. Check server console for details.");
|
|
||||||
PluginLogger.LogError("Download task has been interrupted", ex);
|
|
||||||
}
|
|
||||||
catch (ExecutionException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage(ChatColor.RED + "Download failed : " + ex.getMessage());
|
|
||||||
joueur.sendMessage(ChatColor.RED + "Please check your URL");
|
|
||||||
}
|
|
||||||
catch(IOException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage(ChatColor.RED + "Failed to process the image. Check server console for details.");
|
|
||||||
PluginLogger.LogError("Image processing failed", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
joueur.sendMessage(ChatColor.RED + "An error occured. See the console for details");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void traiterMap(BufferedImage img) throws IOException;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package fr.moribus.imageonmap;
|
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap;
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap.Type;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class TacheTraitementNouvelleMap extends TacheTraitementMap
|
|
||||||
{
|
|
||||||
private final Type type;
|
|
||||||
|
|
||||||
public TacheTraitementNouvelleMap(Player player, URL url, Type type, boolean rs, boolean rn)
|
|
||||||
{
|
|
||||||
super(player, url, rs, rn);
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void traiterMap(BufferedImage img) throws IOException
|
|
||||||
{
|
|
||||||
ImageMap m = ImageMap.Type.createNewMap(type, img, getJoueur());
|
|
||||||
|
|
||||||
m.load();
|
|
||||||
m.give(getJoueur().getInventory());
|
|
||||||
m.save();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,86 +0,0 @@
|
|||||||
package fr.moribus.imageonmap.commands;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.ImageOnMap;
|
|
||||||
import fr.moribus.imageonmap.ImgUtility;
|
|
||||||
import fr.moribus.imageonmap.TacheTraitementMap;
|
|
||||||
import fr.moribus.imageonmap.TacheTraitementNouvelleMap;
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class ImageRenduCommande implements CommandExecutor
|
|
||||||
{
|
|
||||||
Player joueur;
|
|
||||||
boolean renderName, imgSvg;
|
|
||||||
ImageOnMap plugin;
|
|
||||||
boolean resize, rename;
|
|
||||||
|
|
||||||
public ImageRenduCommande(ImageOnMap p)
|
|
||||||
{
|
|
||||||
plugin = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
|
||||||
{
|
|
||||||
// On vérifie si celui qui exécute la commande est bien un joueur
|
|
||||||
if (!ImgUtility.VerifierIdentite(sender))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
joueur = (Player) sender;
|
|
||||||
resize = false;
|
|
||||||
rename = true;
|
|
||||||
|
|
||||||
if (!joueur.hasPermission("imageonmap.userender"))
|
|
||||||
{
|
|
||||||
joueur.sendMessage("You are not allowed to use this command ( " + cmd.getName() + " )!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length < 1)
|
|
||||||
{
|
|
||||||
joueur.sendMessage(ChatColor.RED + "You must enter image url.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
URL url;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
url = new URL(args[0]);
|
|
||||||
}
|
|
||||||
catch (MalformedURLException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("§cInvalid URL.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageMap.Type type = ImageMap.Type.SINGLE;
|
|
||||||
|
|
||||||
if (args.length >= 2)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
type = Enum.valueOf(ImageMap.Type.class, args[1]);
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("Specified map type doesn't exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TacheTraitementMap tache = new TacheTraitementNouvelleMap(joueur, url, type, resize, rename);
|
|
||||||
tache.runTaskTimer(plugin, 0, 5);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,265 +0,0 @@
|
|||||||
package fr.moribus.imageonmap.commands;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.ImageOnMap;
|
|
||||||
import fr.moribus.imageonmap.ImgUtility;
|
|
||||||
import fr.moribus.imageonmap.PluginLogger;
|
|
||||||
import fr.moribus.imageonmap.SavedPoster;
|
|
||||||
import fr.moribus.imageonmap.TacheTraitementMajMap;
|
|
||||||
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;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap;
|
|
||||||
import fr.moribus.imageonmap.map.PosterMap;
|
|
||||||
import fr.moribus.imageonmap.map.SingleMap;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
|
|
||||||
public class MapToolCommand implements CommandExecutor
|
|
||||||
{
|
|
||||||
short id;
|
|
||||||
ImageOnMap plugin;
|
|
||||||
MapView map;
|
|
||||||
Player joueur;
|
|
||||||
Inventory inv;
|
|
||||||
|
|
||||||
public MapToolCommand(ImageOnMap p)
|
|
||||||
{
|
|
||||||
plugin = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
|
||||||
{
|
|
||||||
if (!ImgUtility.VerifierIdentite(sender))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
joueur = (Player) sender;
|
|
||||||
inv = joueur.getInventory();
|
|
||||||
|
|
||||||
if (args.length < 1)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("Map tools usage:"
|
|
||||||
+ "\n/" + ChatColor.GOLD + label + ChatColor.RESET + " get [id]: get the map corresponding to this id"
|
|
||||||
+ "\n/" + ChatColor.GOLD + label + ChatColor.RESET + " delete [id]: remove the map corresponding to this id"
|
|
||||||
+ "\n/" + ChatColor.GOLD + label + ChatColor.RESET + " list: show all ids of maps in your possession");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("get"))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
id = Short.parseShort(args[1]);
|
|
||||||
}
|
|
||||||
catch (NumberFormatException err)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("you must enter a number !");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
SingleMap smap;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
smap = new SingleMap(id);
|
|
||||||
smap.load();
|
|
||||||
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.");
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (IllegalArgumentException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage(ChatColor.RED + "Invalid argument : " + ex.getMessage());
|
|
||||||
}
|
|
||||||
catch(IOException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage(ChatColor.RED + "Unable to load the map. Check server console for details.");
|
|
||||||
PluginLogger.LogError("Could not load the map", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (args[0].equalsIgnoreCase("set"))
|
|
||||||
{
|
|
||||||
ImageMap smap;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (args[1].startsWith("poster"))
|
|
||||||
{
|
|
||||||
smap = new PosterMap(args[1]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
id = Short.parseShort(args[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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(args.length < 3)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("§cYou must enter a valid URL.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
URL url;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
url = new URL(args[2]);
|
|
||||||
}
|
|
||||||
catch (MalformedURLException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("§Invalid URL.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
TacheTraitementMajMap tache = new TacheTraitementMajMap(smap, url, joueur);
|
|
||||||
tache.runTaskTimer(plugin, 0, 5);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (args[0].equalsIgnoreCase("delete"))
|
|
||||||
{
|
|
||||||
if (!joueur.hasPermission("imageonmap.usermmap"))
|
|
||||||
{
|
|
||||||
joueur.sendMessage("You are not allowed to delete map !");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length == 2 && args[1].startsWith("poster"))
|
|
||||||
{
|
|
||||||
SavedPoster poster = new SavedPoster(plugin, args[1]);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
poster.Remove();
|
|
||||||
}
|
|
||||||
catch (IOException ex)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("Unable to remove the entire poster, check the server log for more information");
|
|
||||||
PluginLogger.LogError("Unable to remove the entire poster", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args.length <= 1)
|
|
||||||
{
|
|
||||||
if (joueur.getItemInHand().getType() == Material.MAP)
|
|
||||||
{
|
|
||||||
id = joueur.getItemInHand().getDurability();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
joueur.sendMessage(ChatColor.RED + "You must hold a map or enter an id");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
id = Short.parseShort(args[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 (args[0].equalsIgnoreCase("list"))
|
|
||||||
{
|
|
||||||
String msg = "", msg2 = "";
|
|
||||||
int compteur = 0;
|
|
||||||
ArrayList<String> liste = new ArrayList<String>();
|
|
||||||
|
|
||||||
liste = ImgUtility.getListMapByPlayer(plugin, joueur.getName());
|
|
||||||
|
|
||||||
for (; compteur < liste.size(); compteur++)
|
|
||||||
{
|
|
||||||
msg += liste.get(compteur) + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
SavedPoster tmp = new SavedPoster(plugin);
|
|
||||||
ArrayList<String> listePoster = tmp.getListMapByPlayer(plugin, joueur.getName());
|
|
||||||
for (int i = 0; i < listePoster.size(); i++)
|
|
||||||
{
|
|
||||||
msg2 += listePoster.get(i) + " ";
|
|
||||||
}
|
|
||||||
joueur.sendMessage(msg
|
|
||||||
+ "\nYou have rendered " + ChatColor.DARK_PURPLE + (compteur + 1) + ChatColor.RESET + " pictures");
|
|
||||||
joueur.sendMessage("Your posters: \n" + msg2);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (args[0].equalsIgnoreCase("getrest"))
|
|
||||||
{
|
|
||||||
if (plugin.getRemainingMaps(joueur.getName()) == null)
|
|
||||||
{
|
|
||||||
joueur.sendMessage("All maps have already be placed in your inventory");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
ArrayList<ItemStack> reste = plugin.getRemainingMaps(joueur.getName());
|
|
||||||
ArrayList<ItemStack> restant = new ArrayList<ItemStack>();
|
|
||||||
for (int i = 0; i < reste.size(); i++)
|
|
||||||
{
|
|
||||||
ImgUtility.AddMap(reste.get(i), inv, restant);
|
|
||||||
}
|
|
||||||
if (restant.isEmpty())
|
|
||||||
{
|
|
||||||
plugin.removeRemaingMaps(joueur.getName());
|
|
||||||
joueur.sendMessage("All maps have been placed in your inventory");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
plugin.setRemainingMaps(joueur.getName(), restant);
|
|
||||||
joueur.sendMessage(restant.size() + " maps can't be placed in your inventory. Please run " + ChatColor.GOLD + "/maptool getrest again");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
package fr.moribus.imageonmap.image;
|
|
||||||
|
|
||||||
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 final URL imageURL;
|
|
||||||
private BufferedImage imgSrc;
|
|
||||||
|
|
||||||
public DownloadImageThread(URL imageURL)
|
|
||||||
{
|
|
||||||
this.imageURL = imageURL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BufferedImage call() throws IOException
|
|
||||||
{
|
|
||||||
imgSrc = ImageIO.read(imageURL);
|
|
||||||
|
|
||||||
if(imgSrc == null) throw new IOException("URL does not points to a valid image.");
|
|
||||||
|
|
||||||
return imgSrc;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fr.moribus.imageonmap.image;
|
||||||
|
|
||||||
|
import fr.moribus.imageonmap.PluginLogger;
|
||||||
|
import fr.moribus.imageonmap.worker.Worker;
|
||||||
|
import fr.moribus.imageonmap.worker.WorkerRunnable;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
public class ImageIOExecutor extends Worker
|
||||||
|
{
|
||||||
|
static private ImageIOExecutor instance;
|
||||||
|
|
||||||
|
static public void start()
|
||||||
|
{
|
||||||
|
if(instance != null) stop();
|
||||||
|
instance = new ImageIOExecutor();
|
||||||
|
instance.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void stop()
|
||||||
|
{
|
||||||
|
instance.exit();
|
||||||
|
instance = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageIOExecutor()
|
||||||
|
{
|
||||||
|
super("Image IO");
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void loadImage(final File file, final Renderer mapRenderer)
|
||||||
|
{
|
||||||
|
instance.submitQuery(new WorkerRunnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run() throws Exception
|
||||||
|
{
|
||||||
|
BufferedImage image = ImageIO.read(file);
|
||||||
|
mapRenderer.setImage(image);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,152 +0,0 @@
|
|||||||
package fr.moribus.imageonmap.image;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.image.PosterImage;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.Image;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
|
|
||||||
import org.bukkit.map.MapView;
|
|
||||||
|
|
||||||
|
|
||||||
public class ImageRendererThread extends Thread
|
|
||||||
{
|
|
||||||
private String URL;
|
|
||||||
private BufferedImage imgSrc;
|
|
||||||
private BufferedImage[] img;
|
|
||||||
private PosterImage poster;
|
|
||||||
private boolean estPrete = false, resized;
|
|
||||||
public boolean erreur = false;
|
|
||||||
|
|
||||||
public boolean isErreur()
|
|
||||||
{
|
|
||||||
return erreur;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImageRendererThread(String u, boolean r)
|
|
||||||
{
|
|
||||||
URL = u;
|
|
||||||
resized = r;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BufferedImage[] getImg()
|
|
||||||
{
|
|
||||||
if (estPrete)
|
|
||||||
return img;
|
|
||||||
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Boolean getStatut()
|
|
||||||
{
|
|
||||||
return estPrete;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
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) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
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 PosterImage(canvas);
|
|
||||||
img = poster.getImages();
|
|
||||||
}
|
|
||||||
|
|
||||||
estPrete = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static public 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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
74
src/main/java/fr/moribus/imageonmap/image/MapInitEvent.java
Normal file
74
src/main/java/fr/moribus/imageonmap/image/MapInitEvent.java
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fr.moribus.imageonmap.image;
|
||||||
|
|
||||||
|
import fr.moribus.imageonmap.ImageOnMap;
|
||||||
|
import java.io.File;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.ItemFrame;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||||
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.map.MapView;
|
||||||
|
|
||||||
|
public class MapInitEvent implements Listener
|
||||||
|
{
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChunkLoad(ChunkLoadEvent event)
|
||||||
|
{
|
||||||
|
for (Entity entity : event.getChunk().getEntities())
|
||||||
|
{
|
||||||
|
if (entity instanceof ItemFrame)
|
||||||
|
{
|
||||||
|
ItemStack item = ((ItemFrame)entity).getItem();
|
||||||
|
if (item.getType() == Material.MAP)
|
||||||
|
{
|
||||||
|
MapView map = Bukkit.getMap(item.getDurability());
|
||||||
|
if(!Renderer.isHandled(map)) initMap(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerInv(PlayerItemHeldEvent event)
|
||||||
|
{
|
||||||
|
ItemStack item = event.getPlayer().getInventory().getItem(event.getNewSlot());
|
||||||
|
|
||||||
|
if (item != null && item.getType() == Material.MAP)
|
||||||
|
{
|
||||||
|
MapView map = Bukkit.getMap(item.getDurability());
|
||||||
|
if (!Renderer.isHandled(map)) initMap(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void initMap(MapView map)
|
||||||
|
{
|
||||||
|
File imageFile = ImageOnMap.getPlugin().getImageFile(map.getId());
|
||||||
|
if(imageFile.isFile())
|
||||||
|
{
|
||||||
|
ImageIOExecutor.loadImage(imageFile, Renderer.installRenderer(map));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package fr.moribus.imageonmap.image;
|
package fr.moribus.imageonmap.image;
|
||||||
|
|
||||||
import fr.moribus.imageonmap.map.ImageMap;
|
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,6 +26,9 @@ import java.awt.image.BufferedImage;
|
|||||||
*/
|
*/
|
||||||
public class PosterImage
|
public class PosterImage
|
||||||
{
|
{
|
||||||
|
static private final int WIDTH = 128;
|
||||||
|
static private final int HEIGHT = 128;
|
||||||
|
|
||||||
private BufferedImage[] cutImages;
|
private BufferedImage[] cutImages;
|
||||||
private int lines;
|
private int lines;
|
||||||
private int columns;
|
private int columns;
|
||||||
@ -30,11 +49,11 @@ public class PosterImage
|
|||||||
int originalWidth = originalImage.getWidth();
|
int originalWidth = originalImage.getWidth();
|
||||||
int originalHeight = originalImage.getHeight();
|
int originalHeight = originalImage.getHeight();
|
||||||
|
|
||||||
columns = (int) Math.ceil(originalWidth / ImageMap.WIDTH);
|
columns = (int) Math.ceil(originalWidth / WIDTH);
|
||||||
lines = (int) Math.ceil(originalHeight / ImageMap.HEIGHT);
|
lines = (int) Math.ceil(originalHeight / HEIGHT);
|
||||||
|
|
||||||
remainderX = originalWidth % ImageMap.WIDTH;
|
remainderX = originalWidth % WIDTH;
|
||||||
remainderY = originalHeight % ImageMap.HEIGHT;
|
remainderY = originalHeight % HEIGHT;
|
||||||
|
|
||||||
if(remainderX > 0) columns++;
|
if(remainderX > 0) columns++;
|
||||||
if(remainderY > 0) lines++;
|
if(remainderY > 0) lines++;
|
||||||
@ -43,16 +62,16 @@ public class PosterImage
|
|||||||
cutImages = new BufferedImage[cutImagesCount];
|
cutImages = new BufferedImage[cutImagesCount];
|
||||||
|
|
||||||
int imageX;
|
int imageX;
|
||||||
int imageY = (remainderY - ImageMap.HEIGHT) / 2;
|
int imageY = (remainderY - HEIGHT) / 2;
|
||||||
for(int i = 0; i < lines; i++)
|
for(int i = 0; i < lines; i++)
|
||||||
{
|
{
|
||||||
imageX = (remainderX - ImageMap.WIDTH) / 2;
|
imageX = (remainderX - WIDTH) / 2;
|
||||||
for(int j = 0; j < columns; j++)
|
for(int j = 0; j < columns; j++)
|
||||||
{
|
{
|
||||||
cutImages[i * columns + j] = makeSubImage(originalImage, imageX, imageY);
|
cutImages[i * columns + j] = makeSubImage(originalImage, imageX, imageY);
|
||||||
imageX += ImageMap.WIDTH;
|
imageX += WIDTH;
|
||||||
}
|
}
|
||||||
imageY += ImageMap.HEIGHT;
|
imageY += HEIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +83,7 @@ public class PosterImage
|
|||||||
*/
|
*/
|
||||||
private BufferedImage makeSubImage(BufferedImage originalImage, int x, int y)
|
private BufferedImage makeSubImage(BufferedImage originalImage, int x, int y)
|
||||||
{
|
{
|
||||||
BufferedImage newImage = new BufferedImage(ImageMap.WIDTH, ImageMap.HEIGHT, BufferedImage.TYPE_INT_ARGB);
|
BufferedImage newImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
|
||||||
Graphics graphics = newImage.getGraphics();
|
Graphics graphics = newImage.getGraphics();
|
||||||
|
|
||||||
@ -73,13 +92,6 @@ public class PosterImage
|
|||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private int boundValue(int min, int value, int max)
|
|
||||||
{
|
|
||||||
return Math.max(Math.min(value, max), min);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return the split images
|
* @return the split images
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package fr.moribus.imageonmap.image;
|
package fr.moribus.imageonmap.image;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
@ -8,11 +26,40 @@ import org.bukkit.map.MapView;
|
|||||||
|
|
||||||
public class Renderer extends MapRenderer
|
public class Renderer extends MapRenderer
|
||||||
{
|
{
|
||||||
private boolean isRendered;
|
static public boolean isHandled(MapView map)
|
||||||
private final BufferedImage image;
|
{
|
||||||
public Renderer(BufferedImage image)
|
for(MapRenderer renderer : map.getRenderers())
|
||||||
|
{
|
||||||
|
if(renderer instanceof Renderer) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public Renderer installRenderer(MapView map)
|
||||||
|
{
|
||||||
|
Renderer renderer = new Renderer();
|
||||||
|
removeRenderers(map);
|
||||||
|
map.addRenderer(renderer);
|
||||||
|
return renderer;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void removeRenderers(MapView map)
|
||||||
|
{
|
||||||
|
for(MapRenderer renderer : map.getRenderers())
|
||||||
|
{
|
||||||
|
map.removeRenderer(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private BufferedImage image;
|
||||||
|
|
||||||
|
protected Renderer()
|
||||||
|
{
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Renderer(BufferedImage image)
|
||||||
{
|
{
|
||||||
isRendered = false;
|
|
||||||
this.image = image;
|
this.image = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,10 +67,19 @@ public class Renderer extends MapRenderer
|
|||||||
public void render(MapView v, final MapCanvas canvas, Player p)
|
public void render(MapView v, final MapCanvas canvas, Player p)
|
||||||
{
|
{
|
||||||
//Render only once to avoid overloading the server
|
//Render only once to avoid overloading the server
|
||||||
if (!isRendered)
|
if (image == null) return;
|
||||||
{
|
|
||||||
canvas.drawImage(0, 0, image);
|
canvas.drawImage(0, 0, image);
|
||||||
isRendered = true;
|
image = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BufferedImage getImage()
|
||||||
|
{
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage(BufferedImage image)
|
||||||
|
{
|
||||||
|
this.image = image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,90 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package fr.moribus.imageonmap.map;
|
package fr.moribus.imageonmap.map;
|
||||||
|
|
||||||
import fr.moribus.imageonmap.image.PosterImage;
|
import java.util.HashMap;
|
||||||
import java.awt.image.BufferedImage;
|
import java.util.Map;
|
||||||
import java.io.IOException;
|
import java.util.UUID;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
public abstract class ImageMap implements ConfigurationSerializable
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
public abstract class ImageMap
|
|
||||||
{
|
{
|
||||||
static public enum Type
|
|
||||||
{
|
|
||||||
SINGLE, POSTER;
|
|
||||||
|
|
||||||
static public ImageMap createNewMap(Type type, BufferedImage image, Player player)
|
|
||||||
{
|
|
||||||
switch(type)
|
|
||||||
{
|
|
||||||
case POSTER:
|
|
||||||
return new PosterMap(new PosterImage(image), player);
|
|
||||||
default:
|
|
||||||
return new SingleMap(image, player);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static public Type fromString(String string)
|
|
||||||
{
|
|
||||||
switch(string.toLowerCase())
|
|
||||||
{
|
|
||||||
case "poster":
|
|
||||||
case "multi":
|
|
||||||
return POSTER;
|
|
||||||
default:
|
|
||||||
return SINGLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static public final int WIDTH = 128;
|
static public final int WIDTH = 128;
|
||||||
static public final int HEIGHT = 128;
|
static public final int HEIGHT = 128;
|
||||||
|
|
||||||
protected String imageName;
|
private final UUID userUUID;
|
||||||
protected String ownerName;
|
private String imageName;
|
||||||
protected String worldName;
|
|
||||||
|
|
||||||
public abstract void load() throws IOException;
|
protected ImageMap(UUID userUUID)
|
||||||
public abstract void save() throws IOException;
|
|
||||||
public abstract void give(Inventory inv);
|
|
||||||
public abstract void setImage(BufferedImage image);
|
|
||||||
public abstract void send(Player joueur);
|
|
||||||
|
|
||||||
public ImageMap()
|
|
||||||
{
|
{
|
||||||
this(null, null, null);
|
this.userUUID = userUUID;
|
||||||
}
|
|
||||||
|
|
||||||
public ImageMap(String imageName, String ownerName, String worldName)
|
|
||||||
{
|
|
||||||
this.imageName = imageName;
|
|
||||||
this.ownerName = ownerName;
|
|
||||||
this.worldName = worldName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract short[] getMapsIDs();
|
||||||
|
public abstract boolean managesMap(short mapID);
|
||||||
|
|
||||||
protected void give(Inventory inventory, short mapID)
|
/*** Serialization methods ***/
|
||||||
|
|
||||||
|
protected ImageMap(Map<String, Object> map, UUID userUUID) throws IllegalArgumentException
|
||||||
{
|
{
|
||||||
give(inventory, mapID, getImageName());
|
try
|
||||||
|
{
|
||||||
|
this.userUUID = userUUID;
|
||||||
|
this.imageName = (String) map.get("name");
|
||||||
|
}
|
||||||
|
catch(ClassCastException ex)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void give(Inventory inventory, short mapID, String itemName)
|
protected abstract void postSerialize(Map<String, Object> map);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> serialize()
|
||||||
{
|
{
|
||||||
ItemStack itemMap = new ItemStack(Material.MAP, 1, mapID);
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
if(itemName != null)
|
map.put("name", imageName);
|
||||||
{
|
return map;
|
||||||
ItemMeta meta = itemMap.getItemMeta();
|
|
||||||
meta.setDisplayName(itemName);
|
|
||||||
itemMap.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
inventory.addItem(itemMap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters & Setters
|
|
||||||
|
/*** Getters & Setters ***/
|
||||||
|
|
||||||
|
public UUID getUserUUID()
|
||||||
|
{
|
||||||
|
return userUUID;
|
||||||
|
}
|
||||||
|
|
||||||
public String getImageName()
|
public String getImageName()
|
||||||
{
|
{
|
||||||
@ -95,29 +82,4 @@ public abstract class ImageMap
|
|||||||
{
|
{
|
||||||
this.imageName = imageName;
|
this.imageName = imageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNamed()
|
|
||||||
{
|
|
||||||
return imageName != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getOwnerName()
|
|
||||||
{
|
|
||||||
return ownerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOwnerName(String ownerName)
|
|
||||||
{
|
|
||||||
this.ownerName = ownerName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWorldName()
|
|
||||||
{
|
|
||||||
return worldName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWorldName(String worldName)
|
|
||||||
{
|
|
||||||
this.worldName = worldName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
72
src/main/java/fr/moribus/imageonmap/map/MapManager.java
Normal file
72
src/main/java/fr/moribus/imageonmap/map/MapManager.java
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fr.moribus.imageonmap.map;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
abstract public class MapManager
|
||||||
|
{
|
||||||
|
static private final ArrayList<PlayerMapStore> playerMaps = new ArrayList<PlayerMapStore>();;
|
||||||
|
|
||||||
|
static public void init()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void exit()
|
||||||
|
{
|
||||||
|
playerMaps.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
static public boolean managesMap(short mapID)
|
||||||
|
{
|
||||||
|
synchronized(playerMaps)
|
||||||
|
{
|
||||||
|
for(PlayerMapStore mapStore : playerMaps)
|
||||||
|
{
|
||||||
|
if(mapStore.managesMap(mapID)) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static private PlayerMapStore getPlayerMapStore(UUID playerUUID)
|
||||||
|
{
|
||||||
|
PlayerMapStore store = getExistingPlayerMapStore(playerUUID);
|
||||||
|
if(store == null)
|
||||||
|
{
|
||||||
|
store = new PlayerMapStore(playerUUID);
|
||||||
|
synchronized(playerMaps){playerMaps.add(store);}
|
||||||
|
}
|
||||||
|
return store;
|
||||||
|
}
|
||||||
|
|
||||||
|
static private PlayerMapStore getExistingPlayerMapStore(UUID playerUUID)
|
||||||
|
{
|
||||||
|
synchronized(playerMaps)
|
||||||
|
{
|
||||||
|
for(PlayerMapStore mapStore : playerMaps)
|
||||||
|
{
|
||||||
|
if(mapStore.getUUID().equals(playerUUID)) return mapStore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
49
src/main/java/fr/moribus/imageonmap/map/PlayerMapStore.java
Normal file
49
src/main/java/fr/moribus/imageonmap/map/PlayerMapStore.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fr.moribus.imageonmap.map;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PlayerMapStore
|
||||||
|
{
|
||||||
|
private final UUID playerUUID;
|
||||||
|
private final ArrayList<ImageMap> mapList = new ArrayList<ImageMap>();
|
||||||
|
|
||||||
|
public PlayerMapStore(UUID playerUUID)
|
||||||
|
{
|
||||||
|
this.playerUUID = playerUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean managesMap(short mapID)
|
||||||
|
{
|
||||||
|
for(ImageMap map : mapList)
|
||||||
|
{
|
||||||
|
if(map.managesMap(mapID)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ===== Getters & Setters ===== */
|
||||||
|
|
||||||
|
public UUID getUUID()
|
||||||
|
{
|
||||||
|
return playerUUID;
|
||||||
|
}
|
||||||
|
}
|
@ -1,158 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package fr.moribus.imageonmap.map;
|
package fr.moribus.imageonmap.map;
|
||||||
|
|
||||||
import fr.moribus.imageonmap.ImageOnMap;
|
import java.util.Map;
|
||||||
import fr.moribus.imageonmap.image.Renderer;
|
import java.util.UUID;
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.image.PosterImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.map.MapView;
|
|
||||||
|
|
||||||
public class PosterMap extends ImageMap
|
public class PosterMap extends ImageMap
|
||||||
{
|
{
|
||||||
private PosterImage image;
|
protected short[] mapsIDs;
|
||||||
private final short[] mapsIDs;
|
protected int columnCount;
|
||||||
|
protected int rowCount;
|
||||||
|
|
||||||
private FileConfiguration customConfig = null;
|
public PosterMap(UUID userUUID, short[] mapsIDs, int columnCount, int rowCount)
|
||||||
private File customConfigFile = null;
|
|
||||||
|
|
||||||
public PosterMap(PosterImage image, Player player)
|
|
||||||
{
|
{
|
||||||
super(null, player.getName(), player.getWorld().getName());
|
super(userUUID);
|
||||||
this.image = image;
|
this.mapsIDs = mapsIDs;
|
||||||
|
this.columnCount = columnCount;
|
||||||
mapsIDs = new short[image.getImagesCount()];
|
this.rowCount = rowCount;
|
||||||
for (int i = 0; i < mapsIDs.length; i++)
|
|
||||||
{
|
|
||||||
mapsIDs[i] = Bukkit.createMap(player.getWorld()).getId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public PosterMap(String id) throws Exception
|
|
||||||
{
|
|
||||||
this.imageName = id;
|
|
||||||
List<String> svg = getCustomConfig().getStringList(imageName);
|
|
||||||
if(svg != null && !svg.isEmpty())
|
|
||||||
{
|
|
||||||
this.ownerName = svg.get(0);
|
|
||||||
mapsIDs = new short[svg.size()-1];
|
|
||||||
for(int i = 0; i < mapsIDs.length; i++)
|
|
||||||
{
|
|
||||||
mapsIDs[i] = Short.parseShort(svg.get(i+1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new Exception("Le poster est introuvable.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load()
|
public short[] getMapsIDs()
|
||||||
|
{
|
||||||
|
return mapsIDs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean managesMap(short mapID)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < mapsIDs.length; i++)
|
for(int i = 0; i < mapsIDs.length; i++)
|
||||||
{
|
{
|
||||||
MapView map = Bukkit.getMap(mapsIDs[i]);
|
if(mapsIDs[i] == mapID) return true;
|
||||||
SingleMap.SupprRendu(map);
|
|
||||||
map.addRenderer(new Renderer(image.getImageAt(i)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() throws IOException
|
protected void postSerialize(Map<String, Object> map)
|
||||||
{
|
{
|
||||||
ImageOnMap plugin = ImageOnMap.getPlugin();
|
map.put("columns", columnCount);
|
||||||
|
map.put("rows", rowCount);
|
||||||
for(int i = 0; i < mapsIDs.length; i++)
|
map.put("mapsIDs", mapsIDs);
|
||||||
{
|
|
||||||
short mapID = mapsIDs[i];
|
|
||||||
String mapName = "map" + mapID;
|
|
||||||
File outputfile = new File("./plugins/ImageOnMap/Image/" + mapName + ".png");
|
|
||||||
ImageIO.write(image.getImageAt(i), "png", outputfile);
|
|
||||||
|
|
||||||
// Enregistrement de la map dans la config
|
|
||||||
ArrayList<String> liste = new ArrayList<String>();
|
|
||||||
liste.add(String.valueOf(mapID));
|
|
||||||
liste.add(mapName);
|
|
||||||
liste.add(ownerName);
|
|
||||||
liste.add(worldName);
|
|
||||||
plugin.getCustomConfig().set(mapName, liste);
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.saveCustomConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void give(Inventory inv)
|
|
||||||
{
|
|
||||||
String itemName;
|
|
||||||
for(int i = 0; i < mapsIDs.length; i++)
|
|
||||||
{
|
|
||||||
itemName = "Map (row " + (image.getLineAt(i) + 1) + ", column " + (image.getColumnAt(i) + 1) + ")";
|
|
||||||
give(inv, mapsIDs[i], itemName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setImage(BufferedImage image)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(Player player)
|
|
||||||
{
|
|
||||||
for(short mapID: mapsIDs)
|
|
||||||
{
|
|
||||||
player.sendMap(Bukkit.getMap(mapID));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileConfiguration getCustomConfig()
|
|
||||||
{
|
|
||||||
if (customConfig == null)
|
|
||||||
{
|
|
||||||
reloadCustomConfig();
|
|
||||||
}
|
|
||||||
return customConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveCustomConfig() throws IOException
|
|
||||||
{
|
|
||||||
ImageOnMap plugin = (ImageOnMap)Bukkit.getPluginManager().getPlugin("ImageOnMap");
|
|
||||||
if (customConfig == null || customConfigFile == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getCustomConfig().save(customConfigFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,118 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package fr.moribus.imageonmap.map;
|
package fr.moribus.imageonmap.map;
|
||||||
|
|
||||||
import fr.moribus.imageonmap.ImageOnMap;
|
import java.util.Map;
|
||||||
import fr.moribus.imageonmap.ImgUtility;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.map.MapView;
|
|
||||||
|
|
||||||
import fr.moribus.imageonmap.image.Renderer;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import org.bukkit.map.MapRenderer;
|
|
||||||
|
|
||||||
public class SingleMap extends ImageMap
|
public class SingleMap extends ImageMap
|
||||||
{
|
{
|
||||||
private final short mapID;
|
protected short mapID;
|
||||||
private BufferedImage image;
|
|
||||||
|
|
||||||
public SingleMap(BufferedImage img, Player player)
|
public SingleMap(UUID ownerUUID, short mapID)
|
||||||
{
|
|
||||||
this(img, null, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleMap(BufferedImage image, String imageName, Player player)
|
|
||||||
{
|
|
||||||
super(imageName, player.getName(), player.getWorld().getName());
|
|
||||||
this.mapID = Bukkit.createMap(player.getWorld()).getId();
|
|
||||||
this.image = ImgUtility.scaleImage(image, WIDTH, HEIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SingleMap(short mapID) throws IOException, IllegalArgumentException
|
|
||||||
{
|
{
|
||||||
|
super(ownerUUID);
|
||||||
this.mapID = mapID;
|
this.mapID = mapID;
|
||||||
|
|
||||||
//Testing if the map id exists
|
|
||||||
MapView map = Bukkit.getMap(mapID);
|
|
||||||
if(map == null)
|
|
||||||
throw new IllegalArgumentException("Map ID '" + mapID + "' doesn't exist");
|
|
||||||
|
|
||||||
List<String> svg = ImageOnMap.getPlugin().getCustomConfig().getStringList("map" + mapID);
|
|
||||||
String nomImg = svg.get(1);
|
|
||||||
ownerName = svg.get(2);
|
|
||||||
image = ImageIO.read(new File("./plugins/ImageOnMap/Image/" + nomImg + ".png"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void save() throws IOException
|
public short[] getMapsIDs()
|
||||||
{
|
{
|
||||||
String mapName = "map" + mapID;
|
return new short[]{mapID};
|
||||||
ImageOnMap plugin = ImageOnMap.getPlugin();
|
|
||||||
|
|
||||||
File outputfile = new File("./plugins/ImageOnMap/Image/" + mapName + ".png");
|
|
||||||
ImageIO.write(image, "png", outputfile);
|
|
||||||
|
|
||||||
// Enregistrement de la map dans la config
|
|
||||||
ArrayList<String> liste = new ArrayList<String>();
|
|
||||||
liste.add(String.valueOf(mapID));
|
|
||||||
liste.add(mapName);
|
|
||||||
liste.add(ownerName);
|
|
||||||
liste.add(worldName);
|
|
||||||
plugin.getCustomConfig().set(mapName, liste);
|
|
||||||
plugin.saveCustomConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
|
||||||
public void give(Inventory inventory)
|
|
||||||
{
|
|
||||||
give(inventory, mapID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load()
|
public boolean managesMap(short mapID)
|
||||||
{
|
{
|
||||||
MapView map = Bukkit.getMap(mapID);
|
return this.mapID == mapID;
|
||||||
SingleMap.SupprRendu(map);
|
|
||||||
map.addRenderer(new Renderer(image));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isNamed()
|
protected void postSerialize(Map<String, Object> map)
|
||||||
{
|
{
|
||||||
return imageName != null;
|
map.put("mapID", mapID);
|
||||||
}
|
|
||||||
|
|
||||||
public short getId()
|
|
||||||
{
|
|
||||||
return mapID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setImage(BufferedImage image)
|
|
||||||
{
|
|
||||||
this.image = image;
|
|
||||||
load();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(Player joueur)
|
|
||||||
{
|
|
||||||
joueur.sendMap(Bukkit.getMap(mapID));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SupprRendu(MapView map)
|
|
||||||
{
|
|
||||||
for(MapRenderer renderer : map.getRenderers())
|
|
||||||
{
|
|
||||||
map.removeRenderer(renderer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
108
src/main/java/fr/moribus/imageonmap/worker/Worker.java
Normal file
108
src/main/java/fr/moribus/imageonmap/worker/Worker.java
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fr.moribus.imageonmap.worker;
|
||||||
|
|
||||||
|
import fr.moribus.imageonmap.PluginLogger;
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
|
||||||
|
public abstract class Worker
|
||||||
|
{
|
||||||
|
private final String name;
|
||||||
|
private final ArrayDeque<WorkerRunnable> runQueue = new ArrayDeque<>();
|
||||||
|
|
||||||
|
private final WorkerCallbackManager callbackManager;
|
||||||
|
private Thread thread;
|
||||||
|
|
||||||
|
protected Worker(String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
this.callbackManager = new WorkerCallbackManager(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
if(thread != null && thread.isAlive())
|
||||||
|
{
|
||||||
|
PluginLogger.LogWarning("Restarting " + name + " thread.");
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
thread = createThread();
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exit()
|
||||||
|
{
|
||||||
|
thread.interrupt();
|
||||||
|
thread = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void run()
|
||||||
|
{
|
||||||
|
WorkerRunnable currentRunnable;
|
||||||
|
|
||||||
|
while(!Thread.interrupted())
|
||||||
|
{
|
||||||
|
synchronized(runQueue)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while(runQueue.isEmpty()) runQueue.wait();
|
||||||
|
}
|
||||||
|
catch(InterruptedException ex)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
currentRunnable = runQueue.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
currentRunnable.run();
|
||||||
|
}
|
||||||
|
catch(Throwable ex)
|
||||||
|
{
|
||||||
|
PluginLogger.LogError("Exception from thread " + name, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void submitQuery(WorkerRunnable runnable)
|
||||||
|
{
|
||||||
|
synchronized(runQueue)
|
||||||
|
{
|
||||||
|
runQueue.add(runnable);
|
||||||
|
runQueue.notify();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Thread createThread()
|
||||||
|
{
|
||||||
|
return new Thread()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
Worker.this.run();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package fr.moribus.imageonmap.worker;
|
||||||
|
|
||||||
|
public interface WorkerCallback
|
||||||
|
{
|
||||||
|
public void finished(Object... args);
|
||||||
|
public void errored(Throwable exception);
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package fr.moribus.imageonmap.worker;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
class WorkerCallbackManager implements Runnable
|
||||||
|
{
|
||||||
|
static private final int WATCH_LOOP_DELAY = 5;
|
||||||
|
|
||||||
|
private final HashMap<WorkerRunnable, WorkerCallback> callbacks;
|
||||||
|
private final ArrayDeque<WorkerCallback> callbackQueue;
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public WorkerCallbackManager(String name)
|
||||||
|
{
|
||||||
|
callbacks = new HashMap<>();
|
||||||
|
callbackQueue = new ArrayDeque<>();
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
//Bukkit.getScheduler().runTaskTimer(null, this, 0, WATCH_LOOP_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exit()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Moribus
|
||||||
|
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package fr.moribus.imageonmap.worker;
|
||||||
|
|
||||||
|
public interface WorkerRunnable
|
||||||
|
{
|
||||||
|
public void run() throws Throwable;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user