refactor and changed the header to 2022

This commit is contained in:
Amaury Carrade 2020-06-14 13:27:56 +02:00 committed by Vlammar
parent e911686af4
commit 822c98781e
38 changed files with 528 additions and 259 deletions

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -60,18 +60,24 @@ import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.quartzlib.tools.UpdateChecker; import fr.zcraft.quartzlib.tools.UpdateChecker;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
public final class ImageOnMap extends QuartzPlugin { public final class ImageOnMap extends QuartzPlugin {
private static final String IMAGES_DIRECTORY_NAME = "images"; private static final String IMAGES_DIRECTORY_NAME = "images";
private static final String RENDERS_DIRECTORY_NAME = "renders";
private static final String MAPS_DIRECTORY_NAME = "maps"; private static final String MAPS_DIRECTORY_NAME = "maps";
private static ImageOnMap plugin; private static ImageOnMap plugin;
private final File mapsDirectory;
private File imagesDirectory; private File imagesDirectory;
private File rendersDirectory;
private File mapsDirectory;
private CommandWorkers commandWorker; private CommandWorkers commandWorker;
public ImageOnMap() { public ImageOnMap() {
imagesDirectory = new File(this.getDataFolder(), IMAGES_DIRECTORY_NAME); imagesDirectory = new File(this.getDataFolder(), IMAGES_DIRECTORY_NAME);
rendersDirectory = new File(this.getDataFolder(), RENDERS_DIRECTORY_NAME);
mapsDirectory = new File(this.getDataFolder(), MAPS_DIRECTORY_NAME); mapsDirectory = new File(this.getDataFolder(), MAPS_DIRECTORY_NAME);
plugin = this; plugin = this;
} }
@ -84,6 +90,10 @@ public final class ImageOnMap extends QuartzPlugin {
return imagesDirectory; return imagesDirectory;
} }
public File getRendersDirectory() {
return rendersDirectory;
}
public File getMapsDirectory() { public File getMapsDirectory() {
return mapsDirectory; return mapsDirectory;
} }
@ -92,20 +102,34 @@ public final class ImageOnMap extends QuartzPlugin {
return new File(imagesDirectory, "map" + mapID + ".png"); return new File(imagesDirectory, "map" + mapID + ".png");
} }
public File getRenderFile(int mapID) {
return new File(rendersDirectory, "render" + mapID + ".png");
}
public CommandWorkers getCommandWorker() { public CommandWorkers getCommandWorker() {
return commandWorker; return commandWorker;
} }
@SuppressWarnings("unchecked") private Map<String,File> checkDirs() throws IOException {
Map<String, File> dirs = new HashMap<>();
dirs.put("mapsDirectory", checkPluginDirectory(mapsDirectory));
dirs.put("rendersDirectory", checkPluginDirectory(rendersDirectory));
dirs.put("imagesDirectory", checkPluginDirectory(imagesDirectory));
return dirs;
}
@Override @Override
public void onEnable() { public void onEnable() {
// Creating the images and maps directories if necessary // Creating the images and maps directories if necessary
try { try {
//imagesDirectory = checkPluginDirectory(imagesDirectory, V3Migrator.getOldImagesDirectory(this)); //imagesDirectory = checkPluginDirectory(imagesDirectory, V3Migrator.getOldImagesDirectory(this));
checkPluginDirectory(mapsDirectory); Map<String, File> directories = checkDirs();
checkPluginDirectory(imagesDirectory); mapsDirectory = directories.get("mapsDirectory");
rendersDirectory = directories.get("rendersDirectory");
imagesDirectory = directories.get("imagesDirectory");
} catch (final IOException ex) { } catch (final IOException ex) {
PluginLogger.error("FATAL: " + ex.getMessage()); PluginLogger.error("FATAL: " + ex.getMessage());
//disable the plugin
this.setEnabled(false); this.setEnabled(false);
return; return;
} }
@ -123,9 +147,9 @@ public final class ImageOnMap extends QuartzPlugin {
MapInitEvent.init(); MapInitEvent.init();
MapItemManager.init(); MapItemManager.init();
String commandGroupName = "maptool";
Commands.register( Commands.register(
"maptool", commandGroupName,
NewCommand.class, NewCommand.class,
ListCommand.class, ListCommand.class,
GetCommand.class, GetCommand.class,
@ -138,16 +162,16 @@ public final class ImageOnMap extends QuartzPlugin {
UpdateCommand.class UpdateCommand.class
); );
Commands.registerShortcut("maptool", NewCommand.class, "tomap"); Commands.registerShortcut(commandGroupName, NewCommand.class, "tomap");
Commands.registerShortcut("maptool", ExploreCommand.class, "maps"); Commands.registerShortcut(commandGroupName, ExploreCommand.class, "maps");
Commands.registerShortcut("maptool", GiveCommand.class, "givemap"); Commands.registerShortcut(commandGroupName, GiveCommand.class, "givemap");
if (PluginConfiguration.CHECK_FOR_UPDATES.get()) { if (PluginConfiguration.CHECK_FOR_UPDATES.get()) {
UpdateChecker.boot("imageonmap.26585"); UpdateChecker.boot("imageonmap.26585");
} }
if (PluginConfiguration.COLLECT_DATA.get()) { if (PluginConfiguration.COLLECT_DATA.get()) {
final Metrics metrics = new Metrics(this,5920); final Metrics metrics = new Metrics(this, 5920);
metrics.addCustomChart(new Metrics.SingleLineChart("rendered-images", MapManager::getImagesCount)); metrics.addCustomChart(new Metrics.SingleLineChart("rendered-images", MapManager::getImagesCount));
metrics.addCustomChart(new Metrics.SingleLineChart("used-minecraft-maps", MapManager::getMapCount)); metrics.addCustomChart(new Metrics.SingleLineChart("used-minecraft-maps", MapManager::getMapCount));
} else { } else {

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -40,6 +40,7 @@ package fr.moribus.imageonmap;
import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.tools.PluginLogger; import fr.zcraft.quartzlib.tools.PluginLogger;
import java.util.Set; import java.util.Set;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
@ -79,6 +80,12 @@ public enum Permissions {
* @return {@code true} if this permission is granted to the permissible. * @return {@code true} if this permission is granted to the permissible.
*/ */
public boolean grantedTo(Permissible permissible) { public boolean grantedTo(Permissible permissible) {
//true only if not a player. If the console or a command block as send the command we can assume that it has
//enough privilege
if (permissible == null || permissible.isOp()) {
return true;
}
if (permissible.hasPermission(permission)) { if (permissible.hasPermission(permission)) {
return true; return true;
} }
@ -103,17 +110,13 @@ public enum Permissions {
String prefix = String.format("imageonmap.%slimit.", type.name()); String prefix = String.format("imageonmap.%slimit.", type.name());
for (PermissionAttachmentInfo pai : perms) { for (PermissionAttachmentInfo pai : perms) {
String permString = pai.getPermission().toLowerCase(); String permString = pai.getPermission().toLowerCase();
if (permString.startsWith(prefix)) { if (permString.startsWith(prefix) && pai.getValue()) {
if (pai.getValue()) { try {
try { return Integer.parseInt(permString.split(prefix)[1].trim());
int limit = Integer.parseInt(permString.split(prefix)[1].trim()); } catch (Exception e) {
return limit; PluginLogger.warning(
} catch (Exception e) { I.t("The correct syntax for setting map limit node is: ImageOnMap.mapLimit.X "
PluginLogger.warning( + "where you can replace X with the limit of map a player is allowed to have"));
I.t("The correct syntax for setting map limit node is: ImageOnMap.mapLimit.X "
+ "where you can replace X with the limit of map a player is allowed to have"));
}
} }
} }
} }

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -46,22 +46,24 @@ import java.util.Locale;
public final class PluginConfiguration extends Configuration { public final class PluginConfiguration extends Configuration {
public static ConfigurationItem<Locale> LANG = item("lang", Locale.class); public static final ConfigurationItem<Locale> LANG = item("lang", Locale.class);
public static ConfigurationItem<Boolean> COLLECT_DATA = item("collect-data", true); public static final ConfigurationItem<Boolean> COLLECT_DATA = item("collect-data", true);
public static ConfigurationItem<Boolean> CHECK_FOR_UPDATES = item("check-for-updates", true); public static final ConfigurationItem<Boolean> CHECK_FOR_UPDATES = item("check-for-updates", true);
public static ConfigurationItem<Integer> MAP_GLOBAL_LIMIT = item("map-global-limit", 0, "Limit-map-by-server"); public static final ConfigurationItem<Integer> MAP_GLOBAL_LIMIT =
public static ConfigurationItem<Integer> MAP_PLAYER_LIMIT = item("map-player-limit", 0, "Limit-map-by-player"); item("map-global-limit", 0, "Limit-map-by-server");
public static final ConfigurationItem<Integer> MAP_PLAYER_LIMIT =
item("map-player-limit", 0, "Limit-map-by-player");
public static ConfigurationItem<Boolean> SAVE_FULL_IMAGE = item("save-full-image", true); public static final ConfigurationItem<Boolean> SAVE_FULL_IMAGE = item("save-full-image", true);
public static ConfigurationItem<Integer> LIMIT_SIZE_X = item("limit-map-size-x", 0); public static final ConfigurationItem<Integer> LIMIT_SIZE_X = item("limit-map-size-x", 0);
public static ConfigurationItem<Integer> LIMIT_SIZE_Y = item("limit-map-size-y", 0); public static final ConfigurationItem<Integer> LIMIT_SIZE_Y = item("limit-map-size-y", 0);
public static ConfigurationList<String> IMAGES_HOSTNAMES_WHITELIST = public static final ConfigurationList<String> IMAGES_HOSTNAMES_WHITELIST =
list("images-hostnames-whitelist", String.class); list("images-hostnames-whitelist", String.class);
} }

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -55,7 +55,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
@CommandInfo(name = "delete", usageParameters = "[player name]:<map name> [--confirm]") @CommandInfo(name = "delete", usageParameters = "[player name]:<map name> [--confirm]")
@WithFlags({"confirm"}) @WithFlags({"confirm"})

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -44,7 +44,6 @@ import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo; import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.gui.Gui; import fr.zcraft.quartzlib.components.gui.Gui;
import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.tools.PluginLogger;
import java.util.ArrayList; import java.util.ArrayList;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -74,14 +73,10 @@ public class ExploreCommand extends IoMCommand {
playerName = sender.getName(); playerName = sender.getName();
} }
retrieveUUID(playerName, uuid -> { OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName);
if (sender.isOnline()) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); Gui.open(sender, new MapListGui(offlinePlayer, playerName));
if (sender.isOnline()) { }
Gui.open(sender, new MapListGui(offlinePlayer, playerName));
}
});
} }

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -36,7 +36,6 @@
package fr.moribus.imageonmap.commands.maptool; package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.Permissions; import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
@ -46,6 +45,8 @@ import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.components.i18n.I;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -59,7 +60,7 @@ public class GetCommand extends IoMCommand {
throwInvalidArgument(I.t("Too many parameters!")); throwInvalidArgument(I.t("Too many parameters!"));
return; return;
} }
if (arguments.size() < 1) { if (arguments.isEmpty()) {
throwInvalidArgument(I.t("Too few parameters!")); throwInvalidArgument(I.t("Too few parameters!"));
return; return;
} }
@ -79,28 +80,23 @@ public class GetCommand extends IoMCommand {
mapName = arguments.get(1); mapName = arguments.get(1);
} }
UUID uuid = Bukkit.getOfflinePlayer(playerName).getUniqueId();
if (!sender.isOnline()) {
return;
}
ImageMap map = MapManager.getMap(uuid, mapName);
if (map == null) {
warning(sender, I.t("This map does not exist."));
return;
}
if (map.give(sender)) {
info(I.t("The requested map was too big to fit in your inventory."));
info(I.t("Use '/maptool getremaining' to get the remaining maps."));
}
retrieveUUID(playerName, uuid -> {
if (!sender.isOnline()) {
return;
}
ImageMap map = MapManager.getMap(uuid, mapName);
if (map == null) {
warning(sender, I.t("This map does not exist."));
return;
}
if (map.give(sender)) {
info(I.t("The requested map was too big to fit in your inventory."));
info(I.t("Use '/maptool getremaining' to get the remaining maps."));
}
});
} }
@Override @Override

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -44,6 +44,7 @@ import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo; import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.components.i18n.I;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -66,7 +67,7 @@ public class GiveCommand extends IoMCommand {
throwInvalidArgument(I.t("Too many parameters!")); throwInvalidArgument(I.t("Too many parameters!"));
return; return;
} }
if (arguments.size() < 1) { if (arguments.isEmpty()) {
throwInvalidArgument(I.t("Too few parameters!")); throwInvalidArgument(I.t("Too few parameters!"));
return; return;
} }
@ -101,23 +102,22 @@ public class GiveCommand extends IoMCommand {
} }
final Player sender = playerSender(); final Player sender = playerSender();
UUID uuid = Bukkit.getOfflinePlayer(from).getUniqueId();
UUID uuid2 = Bukkit.getOfflinePlayer(playerName).getUniqueId();
retrieveUUID(from, uuid -> { final ImageMap map = MapManager.getMap(uuid, mapName);
final ImageMap map = MapManager.getMap(uuid, mapName);
if (map == null) { if (map == null) {
warning(sender, I.t("This map does not exist.")); warning(sender, I.t("This map does not exist."));
return; return;
} }
retrieveUUID(playerName, uuid2 -> {
if (Bukkit.getPlayer((uuid2)) != null && Bukkit.getPlayer((uuid2)).isOnline() if (Bukkit.getPlayer((uuid2)) != null && Bukkit.getPlayer((uuid2)).isOnline()
&& map.give(Bukkit.getPlayer(uuid2))) { && map.give(Bukkit.getPlayer(uuid2))) {
info(I.t("The requested map was too big to fit in your inventory.")); info(I.t("The requested map was too big to fit in your inventory."));
info(I.t("Use '/maptool getremaining' to get the remaining maps.")); info(I.t("Use '/maptool getremaining' to get the remaining maps."));
} }
});
});
} }

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -38,6 +38,7 @@ package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions; import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.gui.RenderGui;
import fr.moribus.imageonmap.image.ImageRendererExecutor; import fr.moribus.imageonmap.image.ImageRendererExecutor;
import fr.moribus.imageonmap.image.ImageUtils; import fr.moribus.imageonmap.image.ImageUtils;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
@ -45,6 +46,7 @@ import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap; import fr.moribus.imageonmap.map.PosterMap;
import fr.zcraft.quartzlib.components.commands.CommandException; import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo; import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.gui.Gui;
import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.worker.WorkerCallback; import fr.zcraft.quartzlib.components.worker.WorkerCallback;
import fr.zcraft.quartzlib.tools.PluginLogger; import fr.zcraft.quartzlib.tools.PluginLogger;
@ -122,6 +124,16 @@ public class NewCommand extends IoMCommand {
return; return;
} }
// TODO Add a per-player toggle for the GUI.
if (args.length >= 2) {
ImageRendererExecutor.renderAndNotify(url, scaling, player.getUniqueId(), width, height);
} else {
Gui.open(player, new RenderGui(url));
}
//I try to test if the gui is run correctly
//keep the following as a fallback and for cmd made by console
/*
if (args.length >= 2) { if (args.length >= 2) {
if (args.length >= 3) { if (args.length >= 3) {
try { try {
@ -182,6 +194,8 @@ public class NewCommand extends IoMCommand {
} finally { } finally {
ActionBar.removeMessage(player); ActionBar.removeMessage(player);
} }
*/
} }
@Override @Override

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -88,7 +88,6 @@ public class RenameCommand extends IoMCommand {
@Override @Override
protected List<String> complete() throws CommandException { protected List<String> complete() throws CommandException {
if (args.length == 1) { if (args.length == 1) {
return getMatchingMapNames(playerSender(), args[0]); return getMatchingMapNames(playerSender(), args[0]);
} }

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -52,6 +52,8 @@ import fr.zcraft.quartzlib.tools.text.MessageSender;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -153,73 +155,81 @@ public class UpdateCommand extends IoMCommand {
scaling = ImageUtils.ScalingType.CONTAINED; scaling = ImageUtils.ScalingType.CONTAINED;
} }
//TODO passer en static
//ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
retrieveUUID(playerName, uuid -> {
ImageMap map = MapManager.getMap(uuid, mapName); UUID uuid = Bukkit.getOfflinePlayer(playerName).getUniqueId();
ImageMap map = MapManager.getMap(uuid, mapName);
if (map == null) { if (map == null) {
warning(sender, I.t("This map does not exist.")); warning(sender, I.t("This map does not exist."));
return;
}
URL url1;
try {
url1 = new URL(url);
if (!Permissions.BYPASS_WHITELIST.grantedTo(playerSender) && !checkHostnameWhitelist(url1)) {
throwInvalidArgument(I.t("This hosting website is not trusted, if you think that this is an error "
+ " contact your server administrator"));
return; return;
} }
URL url1; //TODO replace by a check of the load status.(if not loaded load the mapmanager)
try { MapManager.load(false);//we don't want to spam the console each time we reload the mapManager
url1 = new URL(url);
if (!Permissions.BYPASS_WHITELIST.grantedTo(playerSender) && !checkHostnameWhitelist(url1)) {
throwInvalidArgument(I.t("This hosting website is not trusted, if you think that this is an error "
+ " contact your server administrator"));
return;
}
//TODO replace by a check of the load status.(if not loaded load the mapmanager) Integer[] size = {1, 1};
MapManager.load(false);//we don't want to spam the console each time we reload the mapManager if (map.getType() == ImageMap.Type.POSTER) {
size = map.getSize(map.getUserUUID(), map.getId());
Integer[] size = {1, 1};
if (map.getType() == ImageMap.Type.POSTER) {
size = map.getSize(map.getUserUUID(), map.getId());
}
int width = size[0];
int height = size[1];
try {
if (playerSender != null) {
ActionBar.sendPermanentMessage(playerSender, ChatColor.DARK_GREEN + I.t("Updating..."));
}
ImageRendererExecutor
.update(url1, scaling, uuid, map, width, height, new WorkerCallback<ImageMap>() {
@Override
public void finished(ImageMap result) {
if (playerSender != null) {
ActionBar.removeMessage(playerSender);
MessageSender.sendActionBarMessage(playerSender,
ChatColor.DARK_GREEN + I.t("The map was updated using the new image!"));
}
}
@Override
public void errored(Throwable exception) {
if (playerSender != null) {
playerSender
.sendMessage(
I.t("{ce}Map rendering failed: {0}", exception.getMessage()));
}
PluginLogger.warning("Rendering from {0} failed: {1}: {2}",
playerSender.getName(),
exception.getClass().getCanonicalName(),
exception.getMessage());
}
});
} finally {
if (playerSender != null) {
ActionBar.removeMessage(playerSender);
}
}
} catch (MalformedURLException | CommandException ex) {
warning(sender, I.t("Invalid URL."));
} }
});
if (size.length == 0) {
size = new Integer[] {1, 1};
}
int width = size[0];
int height = size[1];
try {
String msg = I.t("Updating...");
if (playerSender != null) {
//TODO tester si player humain
ActionBar.sendPermanentMessage(playerSender, ChatColor.DARK_GREEN + msg);
} else {
PluginLogger.info(msg);
}
ImageRendererExecutor
.update(url1, scaling, uuid, map, width, height, new WorkerCallback<ImageMap>() {
@Override
public void finished(ImageMap result) {
String msg = I.t("The map was updated using the new image!");
if (playerSender != null) {
//TODO tester si player humain
ActionBar.removeMessage(playerSender);
MessageSender.sendActionBarMessage(playerSender,
ChatColor.DARK_GREEN + msg);
} else {
PluginLogger.info(msg);
}
}
@Override
public void errored(Throwable exception) {
if (playerSender != null) {
playerSender
.sendMessage(
I.t("{ce}Map rendering failed: {0}", exception.getMessage()));
}
PluginLogger.warning("Rendering from {0} failed: {1}: {2}",
playerSender.getName(),
exception.getClass().getCanonicalName(),
exception.getMessage());
}
});
} finally {
if (playerSender != null) {
ActionBar.removeMessage(playerSender);
}
}
} catch (MalformedURLException | CommandException ex) {
warning(sender, I.t("Invalid URL."));
}
} }

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -57,8 +57,8 @@ import org.bukkit.inventory.ItemStack;
public class MapDetailGui extends ExplorerGui<Integer> { public class MapDetailGui extends ExplorerGui<Integer> {
private final ImageMap map; private final ImageMap map;
private OfflinePlayer offplayer; private final OfflinePlayer offplayer;
private String name; private final String name;
public MapDetailGui(ImageMap map, OfflinePlayer p, String name) { public MapDetailGui(ImageMap map, OfflinePlayer p, String name) {
super(); super();

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -0,0 +1,180 @@
/*
* Plugin UHCReloaded : Alliances
*
* Copyright ou © ou Copr. Amaury Carrade (2016)
* Idées et réflexions : Alexandre Prokopowicz, Amaury Carrade, "Vayan".
*
* Ce logiciel est régi par la licence CeCILL soumise au droit français et
* respectant les principes de diffusion des logiciels libres. Vous pouvez
* utiliser, modifier et/ou redistribuer ce programme sous les conditions
* de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
* sur le site "http://www.cecill.info".
*
* En contrepartie de l'accessibilité au code source et des droits de copie,
* de modification et de redistribution accordés par cette licence, il n'est
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
* seule une responsabilité restreinte pèse sur l'auteur du programme, le
* titulaire des droits patrimoniaux et les concédants successifs.
*
* A cet égard l'attention de l'utilisateur est attirée sur les risques
* associés au chargement, à l'utilisation, à la modification et/ou au
* développement et à la reproduction du logiciel par l'utilisateur étant
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à
* manipuler et qui le réserve donc à des développeurs et des professionnels
* avertis possédant des connaissances informatiques approfondies. Les
* utilisateurs sont donc invités à charger et tester l'adéquation du
* logiciel à leurs besoins dans des conditions permettant d'assurer la
* sécurité de leurs systèmes et ou de leurs données et, plus généralement,
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
*
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
* pris connaissance de la licence CeCILL, et que vous en avez accepté les
* termes.
*/
package fr.moribus.imageonmap.gui;
import fr.moribus.imageonmap.image.ImageUtils;
import fr.zcraft.quartzlib.components.gui.ActionGui;
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.tools.items.ItemStackBuilder;
import fr.zcraft.quartzlib.tools.items.TextualBanners;
import java.net.URL;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Material;
public class RenderGui extends ActionGui {
final URL url;
boolean resize = false;
int width = 0;
int height = 0;
boolean originalSizeLoaded = false;
int originalWidth = 0;
int originalHeight = 0;
ImageUtils.ScalingType scaling = ImageUtils.ScalingType.NONE;
public RenderGui(URL url) {
this.url = url;
}
@Override
protected void onUpdate() {
setTitle(I.t("Image Editor"));
setHeight(6);
action("toggle_resize", 0, new ItemStackBuilder(Material.PAINTING)
.title(ChatColor.LIGHT_PURPLE, ChatColor.BOLD + I.t("Resize image"))
.loreLine(ChatColor.DARK_GRAY, resize ? I.t("Enabled") : I.t("Disabled"))
.loreSeparator()
.longLore(ChatColor.GRAY,
I.t("You can automatically resize the image to a certain number of blocks (or item frames)."))
.loreSeparator()
.loreLine(ChatColor.BLUE, I.t("Original size (in blocks)"))
.loreLine(ChatColor.GRAY,
originalSizeLoaded ? I.t("{0} × {1}", originalWidth, originalHeight) : I.t("Loading..."))
.loreSeparator()
.longLore(resize ? I.t("{gray}» {white}Click{gray} to disable resize") :
I.t("{gray}» {white}Click{gray} to enable resize"))
);
injectSizeEditor(2, true);
injectSizeEditor(11, false);
}
/**
* Injects the size editor in the GUI.
*
* @param slot The slot where the editor must start.
* @param isWidth True to inject a width-size editor; false to inject a height-editor.
*/
private void injectSizeEditor(int slot, final boolean isWidth) {
final String action_key = isWidth ? "width_" : "height_";
final String currentSize = ChatColor.DARK_GRAY + I.t("Current size: {0} × {1}", width, height);
action(action_key + "_decrement_10", slot++, getBannerButton(false, true, resize)
.title(ChatColor.RED, I.t("- 10"))
.loreLine(currentSize)
.loreSeparator()
.longLore(isWidth
? I.t("{gray}» {white}Click{gray} to decrease the image's width by 10 blocks")
: I.t("{gray}» {white}Click{gray} to decrease the image's height by 10 blocks")
)
);
action(action_key + "_decrement_1", slot++, getBannerButton(false, false, resize)
.title(ChatColor.RED, I.t("- 1"))
.loreLine(currentSize)
.loreSeparator()
.longLore(isWidth
? I.t("{gray}» {white}Click{gray} to decrease the image's width by one block")
: I.t("{gray}» {white}Click{gray} to decrease the image's height by one block")
)
);
action(action_key + "_increment_1", slot++, getBannerButton(true, false, resize)
.title(ChatColor.GREEN, I.t("+ 1"))
.loreLine(currentSize)
.loreSeparator()
.longLore(isWidth
? I.t("{gray}» {white}Click{gray} to increase the image's width by one block")
: I.t("{gray}» {white}Click{gray} to increase the image's height by one block")
)
);
action(action_key + "_increment_10", slot++, getBannerButton(true, true, resize)
.title(ChatColor.GREEN, I.t("+ 10"))
.loreLine(currentSize)
.loreSeparator()
.longLore(isWidth
? I.t("{gray}» {white}Click{gray} to increase the image's width by 10 blocks")
: I.t("{gray}» {white}Click{gray} to increase the image's height by 10 blocks")
)
);
/*(action_key + "_set_values", slot++, getBannerButton(false, false, resize)
.title(ChatColor.BLUE, I.t("set the size"))
.loreLine(currentSize)
.loreSeparator()
.longLore(isWidth
? I.t("{gray}» {white}Click{gray} to set the image's width")
: I.t("{gray}» {white}Click{gray} to set the image's height")
)
);*/
slot++;
}
/**
* Creates a banner for the +/- buttons.
* + are green, - are red
* short steps are light, long steps are dark
* disabled banners are in grayscale
*
* @param positive true for a + banner
* @param longStep true for a darker banner
* @param disabled true for a grayscale banner
* @return The banner in a builder.
*/
private ItemStackBuilder getBannerButton(boolean positive, boolean longStep, boolean disabled) {
//final char symbol = positive ? '+' : '-'; //TODO this need rework have something that work but need QL update
final char symbol = positive ? '*' : '-';
final DyeColor background;
if (disabled) {
background = longStep ? DyeColor.BLACK : DyeColor.GRAY;
} else {
if (positive) {
background = longStep ? DyeColor.GREEN : DyeColor.LIME;
} else {
background = longStep ? DyeColor.RED : DyeColor.PINK;
}
}
return new ItemStackBuilder(TextualBanners.getCharBanner(symbol, background, DyeColor.BLACK));
}
}

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -36,15 +36,20 @@
package fr.moribus.imageonmap.image; package fr.moribus.imageonmap.image;
import fr.moribus.imageonmap.Permissions; import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.PluginConfiguration; import fr.moribus.imageonmap.PluginConfiguration;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager; import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap;
import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.worker.Worker; import fr.zcraft.quartzlib.components.worker.Worker;
import fr.zcraft.quartzlib.components.worker.WorkerAttributes; import fr.zcraft.quartzlib.components.worker.WorkerAttributes;
import fr.zcraft.quartzlib.components.worker.WorkerCallback; import fr.zcraft.quartzlib.components.worker.WorkerCallback;
import fr.zcraft.quartzlib.components.worker.WorkerRunnable; import fr.zcraft.quartzlib.components.worker.WorkerRunnable;
import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.quartzlib.tools.text.ActionBar;
import fr.zcraft.quartzlib.tools.text.MessageSender;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -56,9 +61,47 @@ import java.util.concurrent.Callable;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@WorkerAttributes(name = "Image Renderer", queriesMainThread = true) @WorkerAttributes(name = "Image Renderer", queriesMainThread = true)
public class ImageRendererExecutor extends Worker { public class ImageRendererExecutor extends Worker {
public static void renderAndNotify(final URL url, final ImageUtils.ScalingType scaling, final UUID playerUUID,
final int width, final int height) {
final Player player = Bukkit.getPlayer(playerUUID);
if (player == null) {
return;
}
ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("Rendering..."));
render(url, scaling, player.getUniqueId(), width, height, new WorkerCallback<ImageMap>() {
@Override
public void finished(ImageMap result) {
ActionBar.removeMessage(player);
MessageSender.sendActionBarMessage(player, ChatColor.DARK_GREEN + I.t("Rendering finished!"));
if (result.give(player) && (result instanceof PosterMap && !((PosterMap) result).hasColumnData())) {
player.sendMessage(ChatColor.GRAY + I.t("The rendered map was too big to fit in your inventory."));
player.sendMessage(ChatColor.GRAY + I.t("Use '/maptool getremaining' to get the remaining maps."));
}
}
@Override
public void errored(Throwable exception) {
ActionBar.removeMessage(player);
player.sendMessage(I.t("{ce}Map rendering failed: {0}", exception.getMessage()));
PluginLogger.warning("Rendering from {0} failed: {1}: {2}",
player.getName(),
exception.getClass().getCanonicalName(),
exception.getMessage());
}
});
}
private static URLConnection connecting(URL url) throws IOException { private static URLConnection connecting(URL url) throws IOException {
final URLConnection connection = url.openConnection(); final URLConnection connection = url.openConnection();
connection.addRequestProperty("User-Agent", connection.addRequestProperty("User-Agent",
@ -94,6 +137,7 @@ public class ImageRendererExecutor extends Worker {
public static void render(final URL url, final ImageUtils.ScalingType scaling, final UUID playerUUID, public static void render(final URL url, final ImageUtils.ScalingType scaling, final UUID playerUUID,
final int width, final int height, WorkerCallback<ImageMap> callback) { final int width, final int height, WorkerCallback<ImageMap> callback) {
submitQuery(new WorkerRunnable<ImageMap>() { submitQuery(new WorkerRunnable<ImageMap>() {
@Override @Override
public ImageMap run() throws Throwable { public ImageMap run() throws Throwable {
@ -144,12 +188,13 @@ public class ImageRendererExecutor extends Worker {
} }
// Limits are in place and the player does NOT have rights to avoid them. // Limits are in place and the player does NOT have rights to avoid them.
checkSizeLimit(playerUUID, image); checkSizeLimit(playerUUID, image);
final BufferedImage resizedImage;
if (scaling != ImageUtils.ScalingType.NONE && height <= 1 && width <= 1) { if (scaling != ImageUtils.ScalingType.NONE && height <= 1 && width <= 1) {
ImageMap ret = renderSingle(scaling.resize(image, ImageMap.WIDTH, ImageMap.HEIGHT), playerUUID); resizedImage = scaling.resize(image, ImageMap.WIDTH * width, ImageMap.HEIGHT * height);
image.flush();//Safe to free image.flush();//Safe to free
return ret; return renderSingle(resizedImage, playerUUID);
} }
final BufferedImage resizedImage = resizedImage =
scaling.resize(image, ImageMap.WIDTH * width, ImageMap.HEIGHT * height); scaling.resize(image, ImageMap.WIDTH * width, ImageMap.HEIGHT * height);
image.flush();//Safe to free image.flush();//Safe to free
return renderPoster(resizedImage, playerUUID); return renderPoster(resizedImage, playerUUID);

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -114,11 +114,11 @@ public abstract class ImageMap implements ConfigurationSerializable {
MapManager.getPlayerMapStore(playerUUID).getToolConfig().getConfigurationSection("PlayerMapStore"); MapManager.getPlayerMapStore(playerUUID).getToolConfig().getConfigurationSection("PlayerMapStore");
if (section == null) { if (section == null) {
return null; return new Integer[0];
} }
List<Map<String, Object>> list = (List<Map<String, Object>>) section.getList("mapList"); List<Map<String, Object>> list = (List<Map<String, Object>>) section.getList("mapList");
if (list == null) { if (list == null) {
return null; return new Integer[0];
} }
for (Map<String, Object> tmpMap : list) { for (Map<String, Object> tmpMap : list) {
@ -126,7 +126,7 @@ public abstract class ImageMap implements ConfigurationSerializable {
return new Integer[] {(Integer) tmpMap.get("columns"), (Integer) tmpMap.get("rows")}; return new Integer[] {(Integer) tmpMap.get("columns"), (Integer) tmpMap.get("rows")};
} }
} }
return null; return new Integer[0];
} }
protected static <T> T getFieldValue(Map<String, Object> map, String fieldName) protected static <T> T getFieldValue(Map<String, Object> map, String fieldName)

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -45,6 +45,7 @@ import fr.zcraft.quartzlib.tools.PluginLogger;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -157,7 +158,7 @@ public abstract class MapManager {
public static void notifyModification(UUID playerUUID) { public static void notifyModification(UUID playerUUID) {
getPlayerMapStore(playerUUID).notifyModification(); getPlayerMapStore(playerUUID).notifyModification();
if (autosaveTask == null) { if (autosaveTask == null) {
Bukkit.getScheduler().runTaskLater(ImageOnMap.getPlugin(), new AutosaveRunnable(), SAVE_DELAY); Bukkit.getScheduler().runTaskLater(ImageOnMap.getPlugin(), new AutoSaveRunnable(), SAVE_DELAY);
} }
} }
@ -268,7 +269,7 @@ public abstract class MapManager {
//Loading //Loading
public static void load(boolean verbose) { public static void load(boolean verbose) {
int loadedFilesCount = 0; int loadedFilesCount = 0;
for (File file : ImageOnMap.getPlugin().getMapsDirectory().listFiles()) { for (File file : Objects.requireNonNull(ImageOnMap.getPlugin().getMapsDirectory().listFiles())) {
UUID uuid = getUUIDFromFile(file); UUID uuid = getUUIDFromFile(file);
if (uuid == null) { if (uuid == null) {
continue; continue;
@ -373,7 +374,7 @@ public abstract class MapManager {
return null; return null;
} }
private static class AutosaveRunnable implements Runnable { private static class AutoSaveRunnable implements Runnable {
@Override @Override
public void run() { public void run() {
synchronized (playerMaps) { synchronized (playerMaps) {

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -54,10 +54,11 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class PlayerMapStore implements ConfigurationSerializable { public class PlayerMapStore implements ConfigurationSerializable {
private final UUID playerUUID; private final UUID playerUUID;
private final ArrayList<ImageMap> mapList = new ArrayList<ImageMap>(); private final ArrayList<ImageMap> mapList = new ArrayList<>();
private boolean modified = false; private boolean modified = false;
private int mapCount = 0; private int mapCount = 0;
private FileConfiguration mapConfig = null; private FileConfiguration mapConfig = null;
@ -67,6 +68,7 @@ public class PlayerMapStore implements ConfigurationSerializable {
this.playerUUID = playerUUID; this.playerUUID = playerUUID;
} }
//TODO maybe usefull to merge with the other manages map
public synchronized boolean managesMap(int mapID) { public synchronized boolean managesMap(int mapID) {
for (ImageMap map : mapList) { for (ImageMap map : mapList) {
if (map.managesMap(mapID)) { if (map.managesMap(mapID)) {
@ -83,13 +85,7 @@ public class PlayerMapStore implements ConfigurationSerializable {
if (item.getType() != Material.FILLED_MAP) { if (item.getType() != Material.FILLED_MAP) {
return false; return false;
} }
return managesMap(MapManager.getMapIdFromItemStack(item));
for (ImageMap map : mapList) {
if (map.managesMap(item)) {
return true;
}
}
return false;
} }
public synchronized void addMap(ImageMap map) throws MapManagerException { public synchronized void addMap(ImageMap map) throws MapManagerException {
@ -108,33 +104,27 @@ public class PlayerMapStore implements ConfigurationSerializable {
} }
public synchronized void deleteMap(ImageMap map) throws MapManagerException { public synchronized void deleteMap(ImageMap map) throws MapManagerException {
remove_Map(map); delete_Map(map);
notifyModification(); notifyModification();
} }
private void remove_Map(ImageMap map) throws MapManagerException { private void delete_Map(ImageMap map) throws MapManagerException {
if (!mapList.remove(map)) { if (!mapList.remove(map)) {
throw new MapManagerException(Reason.IMAGEMAP_DOES_NOT_EXIST); throw new MapManagerException(Reason.IMAGEMAP_DOES_NOT_EXIST);
} }
mapCount -= map.getMapCount(); mapCount -= map.getMapCount();
} }
public synchronized boolean mapExists(String id) { public synchronized boolean mapExists(String mapId) {
for (ImageMap map : mapList) { return getMap(mapId) != null;
if (map.getId().equals(id)) {
return true;
}
}
return false;
} }
public String getNextAvailableMapID(String mapId) { public String getNextAvailableMapID(String mapId) {
//TODO check if the value is always greater than the id count
if (!mapExists(mapId)) { if (!mapExists(mapId)) {
return mapId; return mapId;
} }
int id = 0; int id = 0;
do { do {
id++; id++;
} while (mapExists(mapId + "-" + id)); } while (mapExists(mapId + "-" + id));
@ -143,11 +133,12 @@ public class PlayerMapStore implements ConfigurationSerializable {
} }
public synchronized List<ImageMap> getMapList() { public synchronized List<ImageMap> getMapList() {
return new ArrayList(mapList); return new ArrayList<>(mapList);
} }
//TODO refactor to arraylist instead of an array
public synchronized ImageMap[] getMaps() { public synchronized ImageMap[] getMaps() {
return mapList.toArray(new ImageMap[mapList.size()]); return mapList.toArray(new ImageMap[0]);
} }
public synchronized ImageMap getMap(String mapId) { public synchronized ImageMap getMap(String mapId) {
@ -156,7 +147,6 @@ public class PlayerMapStore implements ConfigurationSerializable {
return map; return map;
} }
} }
return null; return null;
} }
@ -202,9 +192,9 @@ public class PlayerMapStore implements ConfigurationSerializable {
/* ****** Configuration Files management ***** */ /* ****** Configuration Files management ***** */
@Override @Override
public Map<String, Object> serialize() { public @NotNull Map<String, Object> serialize() {
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<>();
ArrayList<Map> list = new ArrayList<Map>(); ArrayList<Map> list = new ArrayList<>();
synchronized (this) { synchronized (this) {
for (ImageMap tmpMap : mapList) { for (ImageMap tmpMap : mapList) {
list.add(tmpMap.serialize()); list.add(tmpMap.serialize());

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -158,6 +158,7 @@ public class PosterMap extends ImageMap {
public int getMapIdAtReverseZ(int index, BlockFace orientation, BlockFace bf) { public int getMapIdAtReverseZ(int index, BlockFace orientation, BlockFace bf) {
//TODO maybe a bug there why don't use orientation?
int x = 0; int x = 0;
int y = 0; int y = 0;
switch (bf) { switch (bf) {
@ -193,7 +194,6 @@ public class PosterMap extends ImageMap {
return i; return i;
} }
} }
throw new IllegalArgumentException("Invalid map ID"); throw new IllegalArgumentException("Invalid map ID");
} }

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -76,7 +76,7 @@ class OldSavedMap {
} }
public void serialize(Configuration configuration) { public void serialize(Configuration configuration) {
ArrayList<String> data = new ArrayList<String>(); ArrayList<String> data = new ArrayList<>();
data.add(Short.toString(mapId)); data.add(Short.toString(mapId));
data.add(mapName); data.add(mapName);
data.add(userName); data.add(userName);

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -97,7 +97,7 @@ class OldSavedPoster {
} }
public void serialize(Configuration configuration) { public void serialize(Configuration configuration) {
ArrayList<String> data = new ArrayList<String>(); ArrayList<String> data = new ArrayList<>();
data.add(userName); data.add(userName);
for (short mapId : mapsIds) { for (short mapId : mapsIds) {

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.

View File

@ -1,8 +1,8 @@
/* /*
* Copyright or © or Copr. Moribus (2013) * Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015) * Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2021) * Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2022)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2021) * Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2022)
* *
* This software is a computer program whose purpose is to allow insertion of * This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world. * custom images in a Minecraft world.
@ -43,13 +43,9 @@ import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager; import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap; import fr.moribus.imageonmap.map.PosterMap;
import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.nbt.NBT;
import fr.zcraft.quartzlib.components.nbt.NBTCompound;
import fr.zcraft.quartzlib.components.nbt.NBTList;
import fr.zcraft.quartzlib.tools.PluginLogger; import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.quartzlib.tools.items.GlowEffect; import fr.zcraft.quartzlib.tools.items.GlowEffect;
import fr.zcraft.quartzlib.tools.items.ItemStackBuilder; import fr.zcraft.quartzlib.tools.items.ItemStackBuilder;
import fr.zcraft.quartzlib.tools.reflection.NMSException;
import fr.zcraft.quartzlib.tools.runners.RunTask; import fr.zcraft.quartzlib.tools.runners.RunTask;
import fr.zcraft.quartzlib.tools.text.MessageSender; import fr.zcraft.quartzlib.tools.text.MessageSender;
import fr.zcraft.quartzlib.tools.world.FlatLocation; import fr.zcraft.quartzlib.tools.world.FlatLocation;
@ -59,12 +55,14 @@ import org.bukkit.ChatColor;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Rotation; import org.bukkit.Rotation;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.MapMeta; import org.bukkit.inventory.meta.MapMeta;
//TODO rework splatter effect, using ID is far more stable than nbt tags. //TODO rework splatter effect, using ID is far more stable than nbt tags.
@ -140,7 +138,8 @@ public abstract class SplatterMapManager {
* @return True if the attribute was detected. * @return True if the attribute was detected.
*/ */
public static boolean hasSplatterAttributes(ItemStack itemStack) { public static boolean hasSplatterAttributes(ItemStack itemStack) {
return MapManager.managesMap(itemStack); //TODO only test if bottom left corner
/*
try { try {
final NBTCompound nbt = NBT.fromItemStack(itemStack); final NBTCompound nbt = NBT.fromItemStack(itemStack);
if (!nbt.containsKey("Enchantments")) { if (!nbt.containsKey("Enchantments")) {
@ -154,7 +153,7 @@ public abstract class SplatterMapManager {
} catch (NMSException e) { } catch (NMSException e) {
PluginLogger.error("Unable to get Splatter Map attribute on item", e); PluginLogger.error("Unable to get Splatter Map attribute on item", e);
return false; return false;
} }*/
} }
/** /**
@ -198,6 +197,7 @@ public abstract class SplatterMapManager {
* @param player Player placing map * @param player Player placing map
* @return true if the map was correctly placed * @return true if the map was correctly placed
*/ */
@SuppressWarnings("checkstyle:VariableDeclarationUsageDistance")
public static boolean placeSplatterMap(ItemFrame startFrame, Player player, PlayerInteractEntityEvent event) { public static boolean placeSplatterMap(ItemFrame startFrame, Player player, PlayerInteractEntityEvent event) {
ImageMap map = MapManager.getMap(player.getInventory().getItemInMainHand()); ImageMap map = MapManager.getMap(player.getInventory().getItemInMainHand());
@ -229,8 +229,6 @@ public abstract class SplatterMapManager {
int i = 0; int i = 0;
for (ItemFrame frame : surface.frames) { for (ItemFrame frame : surface.frames) {
BlockFace bf = WorldUtils.get4thOrientation(player.getLocation());
int id = poster.getMapIdAtReverseZ(i, bf, startFrame.getFacing());
Rotation rot = Rotation.NONE; Rotation rot = Rotation.NONE;
switch (frame.getFacing()) { switch (frame.getFacing()) {
case UP: case UP:
@ -241,12 +239,25 @@ public abstract class SplatterMapManager {
default: default:
//throw new IllegalStateException("Unexpected value: " + frame.getFacing()); //throw new IllegalStateException("Unexpected value: " + frame.getFacing());
} }
BlockFace bf = WorldUtils.get4thOrientation(player.getLocation());
int id = poster.getMapIdAtReverseZ(i, bf, startFrame.getFacing());
//Rotation management relative to player rotation the default position is North, //Rotation management relative to player rotation the default position is North,
// when on ceiling we flipped the rotation // when on ceiling we flipped the rotation
RunTask.later(() -> { RunTask.later(() -> {
addPropertiesToFrames(player, frame); addPropertiesToFrames(player, frame);
frame.setItem(
new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem()); ItemStack item = new ItemStack(Material.MAP, 1);
ItemMeta meta = item.getItemMeta();
PluginLogger.info(meta.getAttributeModifiers().toString());
for (AttributeModifier value : meta.getAttributeModifiers().values()) {
PluginLogger.info("blabla");
PluginLogger.info("" + value);
}
item.setItemMeta(meta);
frame.setItem(item);
//new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem());
}, 5L); }, 5L);
if (i == 0) { if (i == 0) {