Merge pull request #135 from zDevelopers/command_rewrite

Command rewrite
This commit is contained in:
Vlammar 2021-04-05 16:24:09 +02:00 committed by GitHub
commit 648121f81b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 555 additions and 855 deletions

View File

@ -93,7 +93,7 @@
<dependency>
<groupId>fr.zcraft</groupId>
<artifactId>quartzlib</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>org.bstats</groupId>

View File

@ -38,15 +38,11 @@ package fr.moribus.imageonmap;
import fr.moribus.imageonmap.commands.maptool.DeleteCommand;
import fr.moribus.imageonmap.commands.maptool.DeleteOtherCommand;
import fr.moribus.imageonmap.commands.maptool.ExploreCommand;
import fr.moribus.imageonmap.commands.maptool.ExploreOtherCommand;
import fr.moribus.imageonmap.commands.maptool.GetCommand;
import fr.moribus.imageonmap.commands.maptool.GetOtherCommand;
import fr.moribus.imageonmap.commands.maptool.GetRemainingCommand;
import fr.moribus.imageonmap.commands.maptool.GiveCommand;
import fr.moribus.imageonmap.commands.maptool.ListCommand;
import fr.moribus.imageonmap.commands.maptool.ListOtherCommand;
import fr.moribus.imageonmap.commands.maptool.MigrateCommand;
import fr.moribus.imageonmap.commands.maptool.NewCommand;
import fr.moribus.imageonmap.commands.maptool.RenameCommand;
@ -74,6 +70,7 @@ public final class ImageOnMap extends QuartzPlugin {
private static ImageOnMap plugin;
private final File mapsDirectory;
private File imagesDirectory;
private CommandWorkers commandWorker;
public ImageOnMap() {
imagesDirectory = new File(this.getDataFolder(), IMAGES_DIRECTORY_NAME);
@ -97,6 +94,9 @@ public final class ImageOnMap extends QuartzPlugin {
return new File(imagesDirectory, "map" + mapID + ".png");
}
public CommandWorkers getCommandWorker() {
return commandWorker;
}
@SuppressWarnings("unchecked")
@Override
@ -113,9 +113,9 @@ public final class ImageOnMap extends QuartzPlugin {
saveDefaultConfig();
commandWorker = loadComponent(CommandWorkers.class);
loadComponents(I18n.class, Gui.class, Commands.class, PluginConfiguration.class, ImageIOExecutor.class,
ImageRendererExecutor.class, CommandWorkers.class);
ImageRendererExecutor.class);
//Init all the things !
I18n.setPrimaryLocale(PluginConfiguration.LANG.get());
@ -129,23 +129,19 @@ public final class ImageOnMap extends QuartzPlugin {
"maptool",
NewCommand.class,
ListCommand.class,
ListOtherCommand.class,
GetCommand.class,
GetOtherCommand.class,
RenameCommand.class,
DeleteCommand.class,
DeleteOtherCommand.class,
GiveCommand.class,
GetRemainingCommand.class,
ExploreCommand.class,
ExploreOtherCommand.class,
MigrateCommand.class,
UpdateCommand.class
);
Commands.registerShortcut("maptool", NewCommand.class, "tomap");
Commands.registerShortcut("maptool", ExploreCommand.class, "maps");
Commands.registerShortcut("maptool", GiveCommand.class, "mapgive");
Commands.registerShortcut("maptool", GiveCommand.class, "givemap");
if (PluginConfiguration.CHECK_FOR_UPDATES.get()) {
UpdateChecker.boot("imageonmap.26585");

View File

@ -43,61 +43,15 @@ import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.i18n.I;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.entity.Player;
public abstract class IoMCommand extends Command {
protected ImageMap getMapFromArgs() throws CommandException {
return getMapFromArgs(playerSender(), 0, true);
}
//TODO:Add the quote system to zlib and refactor this
protected ImageMap getMapFromArgs(Player player, int index) throws CommandException {
if (args.length <= index) {
throwInvalidArgument(I.t("You need to give a map name."));
}
StringBuilder mapName = new StringBuilder(args[index]);
for (int i = index + 1, c = args.length; i < c; i++) {
mapName.append(" ").append(args[i]);
}
String regex = "((\"([^\\\"]*(\\\\\\\")*)*([^\\\\\\\"]\"))|([^\\\"\\s\\\\]*(\\\\\\s)*[\\\\]*)*\"?)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(mapName.toString());
StringBuilder result = new StringBuilder();
//matcher.find();
result.append(matcher.group(0));
if (result != null) {
if (result.charAt(0) == '\"') {
if (result.length() == 1) {
result.deleteCharAt(0);
} else if (result.charAt(result.length() - 1) == '\"') {
result = result.deleteCharAt(result.length() - 1);
if (result != null && !result.equals("") && result.charAt(0) == '\"') {
mapName = new StringBuilder(result.deleteCharAt(0).toString());
}
}
}
}
mapName = new StringBuilder(mapName.toString().trim());
ImageMap map;
map = MapManager.getMap(player.getUniqueId(), mapName.toString());
if (map == null) {
error(I.t("This map does not exist."));
}
return map;
}
protected ImageMap getMapFromArgs(Player player, int index, boolean expand) throws CommandException {
if (args.length <= index) {
throwInvalidArgument(I.t("You need to give a map name."));
@ -122,6 +76,61 @@ public abstract class IoMCommand extends Command {
return map;
}
protected ArrayList<String> getArgs() {
ArrayList<String> arguments = new ArrayList<>();
//State of the automaton, can read word like:
//name_here; "name here"
int state = 0;
StringBuilder s = new StringBuilder();
for (String arg : args) {
if (arg.startsWith("http:") || arg.startsWith("https:")) {
arguments.add(arg);
continue;
}
if (state == 0) {
s = new StringBuilder();
} else {
s.append(" ");
}
for (char c : arg.toCharArray()) {
switch (state) {
case 0:
if (c == '\"') {
state = 1;
} else {
//If we read a : that means that we are on a new argument example:"hello"
if (c == ':') {
arguments.add(s.toString());
s = new StringBuilder();
} else {
s = s.append(c);
}
}
break;
case 1:
if (c == '\"') {
arguments.add(s.toString());
s = new StringBuilder();
state = 0;
} else {
s = s.append(c);
}
break;
default:
throw new IllegalStateException("Unexpected value: " + state);
}
}
if (s.length() > 0 && state != 1) {
arguments.add(s.toString());
}
}
return arguments;
}
protected List<String> getMatchingMapNames(Player player, String prefix) {
return getMatchingMapNames(MapManager.getMapList(player.getUniqueId()), prefix);
}

View File

@ -36,6 +36,7 @@
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
@ -47,16 +48,18 @@ import fr.zcraft.quartzlib.components.commands.WithFlags;
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.rawtext.RawText;
import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.quartzlib.tools.text.RawMessage;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "delete", usageParameters = "<map name> [--confirm]")
@CommandInfo(name = "delete", usageParameters = "[player name]:<map name> [--confirm]")
@WithFlags({"confirm"})
public class DeleteCommand extends IoMCommand {
private static RawText deleteMsg(Class klass, ImageMap map) {
private static RawText deleteMsg(Class klass, String playerName, ImageMap map) {
return new RawText(I.t("You are going to delete") + " ")
.then(map.getId())
.color(ChatColor.GOLD)
@ -65,29 +68,73 @@ public class DeleteCommand extends IoMCommand {
.then(I.t("[Confirm]"))
.color(ChatColor.GREEN)
.hover(new RawText(I.t("{red}This map will be deleted {bold}forever{red}!")))
.command(klass, map.getId(), "--confirm")
.command(klass, playerName + ":" + "\"" + map.getId() + "\"", "--confirm")
.build();
}
@Override
protected void run() throws CommandException {
ImageMap map = getMapFromArgs();
ArrayList<String> arguments = getArgs();
final boolean confirm = hasFlag("confirm");
if (!hasFlag("confirm")) {
RawText msg = deleteMsg(getClass(), map);
send(msg);
} else {
Player player = playerSender();
MapManager.clear(player.getInventory(), map);
try {
MapManager.deleteMap(map);
info(I.t("Map successfully deleted."));
} catch (MapManagerException ex) {
PluginLogger.warning(I.t("A non-existent map was requested to be deleted", ex));
warning(I.t("This map does not exist."));
}
if (arguments.size() > 3 || (arguments.size() > 2 && !confirm)) {
throwInvalidArgument(I.t("Too many parameters!"));
return;
}
if (arguments.size() < 1) {
throwInvalidArgument(I.t("Too few parameters!"));
return;
}
final String playerName;
final String mapName;
final Player sender = playerSender();
if (arguments.size() == 2 || arguments.size() == 3) {
if (!Permissions.DELETEOTHER.grantedTo(sender)) {
throwNotAuthorized();
return;
}
playerName = arguments.get(0);
mapName = arguments.get(1);
} else {
playerName = sender.getName();
mapName = arguments.get(0);
}
//TODO passer en static
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
if (uuid == null) {
warning(sender, I.t("The player {0} does not exist.", playerName));
return;
}
ImageMap map = MapManager.getMap(uuid, mapName);
if (map == null) {
warning(sender, I.t("This map does not exist."));
return;
}
if (!confirm) {
RawText msg = deleteMsg(getClass(), playerName, map);
RawMessage.send(sender, msg);
} else {
if (sender != null && sender.isOnline() && sender.getInventory() != null) {
MapManager.clear(sender.getInventory(), map);
}
try {
MapManager.deleteMap(map);
success(sender, I.t("Map successfully deleted."));
} catch (MapManagerException ex) {
PluginLogger.warning(I.t("A non-existent map was requested to be deleted", ex));
warning(sender, I.t("This map does not exist."));
}
}
});
}
@Override

View File

@ -1,113 +0,0 @@
/*
* Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2020)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2020)
*
* This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.MapManagerException;
import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.commands.WithFlags;
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.tools.PluginLogger;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "deleteother", usageParameters = "<player name> <map name>")
@WithFlags({"confirm"})
public class DeleteOtherCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
if (args.length < 2) {
warning(I.t("Not enough parameters! Usage: /maptool deleteother <playername> <mapname>"));
return;
}
Player player = null;
UUID uuid = null;
OfflinePlayer op = null;
player = Bukkit.getPlayer(args[0]);
if (player == null) {
op = Bukkit.getOfflinePlayer(args[0]);
if (op.hasPlayedBefore()) {
uuid = op.getUniqueId();
} else {
warning(I.t("We've never seen that player before!"));
}
} else {
uuid = player.getUniqueId();
}
if (player == null) {
warning(I.t("Player not found"));
return;
}
ImageMap map = getMapFromArgs(player, 1, true);
//if (player != null) {
MapManager.clear(player.getInventory(), map);
//}
try {
MapManager.deleteMap(map);
info(I.t("{gray}Map successfully deleted."));
} catch (MapManagerException ex) {
PluginLogger.warning(I.t("A non-existent map was requested to be deleted", ex));
warning(ChatColor.RED + (I.t("This map does not exist.")));
}
}
@Override
protected List<String> complete() throws CommandException {
if (args.length == 1) {
return getMatchingMapNames(playerSender(), args[0]);
}
return null;
}
@Override
public boolean canExecute(CommandSender sender) {
return Permissions.DELETEOTHER.grantedTo(sender);
}
}

View File

@ -37,6 +37,7 @@
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.gui.MapListGui;
@ -44,42 +45,48 @@ import fr.zcraft.quartzlib.components.commands.CommandException;
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.tools.PluginLogger;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "explore")
@CommandInfo(name = "explore",usageParameters = "[player name]")
public class ExploreCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
if (args.length < 1) {
Gui.open(playerSender(), new MapListGui(playerSender()));
} else {
if (Permissions.LISTOTHER.grantedTo(sender)) {
String name = args[0];
Player sender = playerSender();
offlinePlayerParameter(0, uuid -> {
if (uuid == null) {
try {
throwInvalidArgument(I.t("Player not found."));
} catch (CommandException e) {
PluginLogger.error("CommandException " + e);
return;
}
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
if (offlinePlayer != null) {
Gui.open(sender, new MapListGui(offlinePlayer, name));
} else {
PluginLogger.warning(I.t("Can't find player"));
}
});
}
ArrayList<String> arguments = getArgs();
if (arguments.size() > 1) {
throwInvalidArgument(I.t("Too many parameters!"));
return;
}
final String playerName;
final Player sender = playerSender();
if (arguments.size() == 1) {
if (!Permissions.LISTOTHER.grantedTo(sender)) {
throwNotAuthorized();
return;
}
playerName = arguments.get(0);
} else {
playerName = sender.getName();
}
//TODO passer en static
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
if (uuid == null) {
warning(sender, I.t("The player {0} does not exist.", playerName));
return;
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
if (sender.isOnline()) {
Gui.open(sender, new MapListGui(offlinePlayer,playerName));
}
});
}
@Override

View File

@ -1,86 +0,0 @@
/*
* Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2020)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2020)
*
* This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.gui.MapListGui;
import fr.zcraft.quartzlib.components.commands.CommandException;
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.tools.PluginLogger;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "exploreother")
public class ExploreOtherCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
if (args.length < 1) {
warning(I.t("Not enough parameters! Usage: /maptool exploreother <playername>"));
return;
}
String name = args[0];
Player sender = playerSender();
offlinePlayerParameter(0, uuid -> {
if (uuid == null) {
try {
throwInvalidArgument(I.t("Player not found."));
} catch (CommandException e) {
PluginLogger.error("CommandException " + e);
return;
}
}
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
if (offlinePlayer != null) {
Gui.open(sender, new MapListGui(offlinePlayer, name));
} else {
PluginLogger.warning(I.t("Can't find player"));
return;
}
});
}
@Override
public boolean canExecute(CommandSender sender) {
return Permissions.LISTOTHER.grantedTo(sender);
}
}

View File

@ -36,24 +36,73 @@
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "get")
@CommandInfo(name = "get",usageParameters = "[player name]:<map name>")
public class GetCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
Player player = playerSender();
if (getMapFromArgs().give(player)) {
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."));
ArrayList<String> arguments = getArgs();
if (arguments.size() > 2) {
throwInvalidArgument(I.t("Too many parameters!"));
return;
}
if (arguments.size() < 1) {
throwInvalidArgument(I.t("Too few parameters!"));
return;
}
final String playerName;
final String mapName;
final Player sender = playerSender();
if (arguments.size() == 1) {
playerName = sender.getName();
mapName = arguments.get(0);
} else {
if (!Permissions.GETOTHER.grantedTo(sender)) {
throwNotAuthorized();
return;
}
playerName = arguments.get(0);
mapName = arguments.get(1);
}
//TODO passer en static
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
if (!sender.isOnline()) {
return;
}
if (uuid == null) {
warning(sender, I.t("The player {0} does not exist.", playerName));
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

View File

@ -1,99 +0,0 @@
/*
* Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2020)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2020)
*
* This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "getother", usageParameters = "<PlayerName> <MapName>")
public class GetOtherCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
if (args.length < 2) {
warning(I.t("Not enough parameters! Usage: /maptool getother <playername> <mapname>"));
return;
}
Player player = null;
UUID uuid = null;
player = Bukkit.getPlayer(args[0]);
if (player == null) {
OfflinePlayer op = Bukkit.getOfflinePlayer(args[0]);
if (op.hasPlayedBefore()) {
uuid = op.getUniqueId();
} else {
warning(I.t("We've never seen that player before!"));
}
return;
} else {
uuid = player.getUniqueId();
}
ImageMap map = null;
String mapName = "";
mapName = args[1];
if (args.length > 2) {
for (int i = 2; i < args.length; i++) {
mapName += (" " + args[i - 1]);
}
}
map = MapManager.getMap(uuid, mapName);
if (map != null) {
map.give(playerSender());
} else {
warning(I.t("Unknown map {0}", mapName));
}
}
@Override
public boolean canExecute(CommandSender sender) {
return Permissions.GETOTHER.grantedTo(sender);
}
}

View File

@ -36,6 +36,7 @@
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
@ -43,102 +44,106 @@ import fr.moribus.imageonmap.map.MapManager;
import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.tools.mojang.UUIDFetcher;
import java.io.IOException;
import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "give", usageParameters = "<Player> <MapName> or <Player> <MapName> <Player where to find the map>")
@CommandInfo(name = "give", usageParameters = "<player name> [playerFrom]:<map name>")
public class GiveCommand extends IoMCommand {
//TODO passer avec une reconnaissance player/UUID, par défaut
/**
* Parse an argument given at a specific index, it will return a player depending on the given prefixe.
* Can be player:< username > or uuid:< uuid >
*
* @param index The index.
* @return The retrieved player.
* @throws CommandException If the value is invalid.
*
*/
private OfflinePlayer parse(int index) throws CommandException {
String s = args[index].trim();
String[] subs = s.split(":");
//try {
//
if (subs.length == 1) {
return null;//temp
//return offlinePlayerParameter(index);
}
switch (subs[0]) {
case "player":
return null;//temp
// return offlinePlayerParameter(subs[1]);
case "uuid":
StringBuffer string = new StringBuffer(subs[1].toLowerCase());
//if there are no '-'
if (string.length() == 32) {
//we try to fix it by adding - at pos 8,12,16,20
Integer[] pos = {20, 16, 12, 8};
for (int i : pos) {
string = string.insert(i, "-");
}
}
//if the given uuid is well formed with 8-4-4-4-12 = 36 chars in length (including '-')
if (string.length() == 36) {
return Bukkit.getOfflinePlayer(UUID.fromString(string.toString()));
}
throwInvalidArgument(
I.t("Invalid uuid, please provide an uuid of this form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
+ " or xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
break;
case "bank":
throwInvalidArgument(I.t("Not supported yet"));
break;
default:
throwInvalidArgument(I.t("Invalid prefix, valid one are: player | uuid"));
}
/*} catch (InterruptedException | ExecutionException e) {
PluginLogger.warning(I.t("Can't access to mojang API to check the player UUID"));
}*/
return null;
}
@Override
protected void run() throws CommandException {
if (args.length < 2) {
throwInvalidArgument(I.t("You must give a valid player name and a map name."));
return;
}
final Player p = getPlayerParameter(0);
ArrayList<String> arguments = getArgs();
ImageMap map;
//TODO add support for map name with spaces "cool name" or name or "name" "cool name with a \" and some stuff"
// should work
OfflinePlayer player = null;
if (arguments.size() > 3) {
throwInvalidArgument(I.t("Too many parameters!"));
return;
}
if (arguments.size() < 1) {
throwInvalidArgument(I.t("Too few parameters!"));
return;
}
final String mapName;
final String from;
final String playerName;
final Player playerSender;
Player playerSender1;
try {
playerSender1 = playerSender();
} catch (CommandException ignored) {
if (arguments.size() == 2) {
throwInvalidArgument(I.t("Player name is required from the console"));
}
playerSender1 = null;
}
playerSender = playerSender1;
if (arguments.size() == 2) {
from = playerSender.getName();
playerName = arguments.get(0);
mapName = arguments.get(1);
} else {
if (arguments.size() == 3) {
from = arguments.get(1);
playerName = arguments.get(0);
mapName = arguments.get(2);
} else {
from = "";
playerName = "";
mapName = "";
}
}
if (args.length < 4) {
if (args.length == 2) {
player = playerSender();
final Player sender = playerSender();
//TODO passer en static
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(from, uuid -> {
if (uuid == null) {
warning(sender, I.t("The player {0} does not exist.", from));
return;
}
if (args.length == 3) {
player = parse(2);
}
map = MapManager.getMap(player.getUniqueId(), args[1]);
final ImageMap map = MapManager.getMap(uuid, mapName);
if (map == null) {
throwInvalidArgument(I.t("Map not found"));
warning(sender, I.t("This map does not exist."));
return;
}
map.give(p);
}
try {
UUID uuid2 = UUIDFetcher.fetch(playerName);
if (uuid2 == null) {
warning(sender, I.t("The player {0} does not exist.", playerName));
return;
}
if (Bukkit.getPlayer((uuid2)) == null || !Bukkit.getPlayer((uuid2)).isOnline()) {
warning(sender, I.t("The player {0} is not connected.", playerName));
return;
}
if (Bukkit.getPlayer((uuid2)) != null && Bukkit.getPlayer((uuid2)).isOnline()
&& map.give(Bukkit.getPlayer(uuid2))) {
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."));
}
} catch (IOException | InterruptedException e) {
try {
throwInvalidArgument(I.t("The player {0} does not exist.", playerName));
} catch (CommandException ex) {
ex.printStackTrace();
}
return;
}
});
}
@Override

View File

@ -36,6 +36,7 @@
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
@ -47,34 +48,68 @@ import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.rawtext.RawText;
import fr.zcraft.quartzlib.components.rawtext.RawTextPart;
import fr.zcraft.quartzlib.tools.text.RawMessage;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "list")
@CommandInfo(name = "list", usageParameters = "[player name]")
public class ListCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
Player player = playerSender();
List<ImageMap> mapList = MapManager.getMapList(player.getUniqueId());
if (mapList.isEmpty()) {
info(I.t("No map found."));
ArrayList<String> arguments = getArgs();
if (arguments.size() > 1) {
throwInvalidArgument(I.t("Too many parameters!"));
return;
}
info(I.tn("{white}{bold}{0} map found.", "{white}{bold}{0} maps found.", mapList.size()));
String playerName;
if (arguments.size() == 1) {
if (!Permissions.LISTOTHER.grantedTo(sender)) {
throwNotAuthorized();
return;
}
RawTextPart rawText = new RawText("");
rawText = addMap(rawText, mapList.get(0));
for (int i = 1, c = mapList.size(); i < c; i++) {
rawText = rawText.then(", ").color(ChatColor.GRAY);
rawText = addMap(rawText, mapList.get(i));
playerName = arguments.get(0);
} else {
playerName = playerSender().getName();
}
RawMessage.send(player, rawText.build());
final Player sender = playerSender();
//TODO passer en static
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
List<ImageMap> mapList = MapManager.getMapList(uuid);
if (uuid == null) {
try {
throwInvalidArgument(I.t("Player {} not found.", playerName));
} catch (CommandException e) {
e.printStackTrace();
}
return;
}
if (mapList.isEmpty()) {
info(sender, I.t("No map found."));
return;
}
String message = I.tn("{white}{bold}{0} map found.",
"{white}{bold}{0} maps found.",
mapList.size());
info(sender, I.tn("{white}{bold}{0} map found.", "{white}{bold}{0} maps found.", mapList.size()));
RawTextPart rawText = new RawText("");
rawText = addMap(rawText, mapList.get(0));
//TODO pagination chat
for (int i = 1, c = mapList.size(); i < c; i++) {
rawText = rawText.then(", ").color(ChatColor.GRAY);
rawText = addMap(rawText, mapList.get(i));
}
RawMessage.send(sender, rawText.build());
});
}
private RawTextPart<?> addMap(RawTextPart<?> rawText, ImageMap map) {

View File

@ -1,128 +0,0 @@
/*
* Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2020)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2020)
*
* This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap;
import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.rawtext.RawText;
import fr.zcraft.quartzlib.components.rawtext.RawTextPart;
import fr.zcraft.quartzlib.tools.text.RawMessage;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "listother", usageParameters = "<PlayerName>")
public class ListOtherCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
if (args.length < 1) {
warning(I.t("Not enough parameters! Usage: /maptool listother <playername>"));
return;
}
Player player = null;
UUID uuid = null;
player = Bukkit.getPlayer(args[0]);
if (player == null) {
OfflinePlayer op = Bukkit.getOfflinePlayer(args[0]);
if (op.hasPlayedBefore()) {
uuid = op.getUniqueId();
} else {
warning(I.t("We've never seen that player before!"));
}
} else {
uuid = player.getUniqueId();
}
List<ImageMap> mapList = null;
try {
mapList = MapManager.getMapList(uuid);
} catch (Exception e) {
return;
}
if (mapList.isEmpty()) {
info(I.t("No map found."));
return;
}
info(I.tn("{white}{bold}{0} map found.", "{white}{bold}{0} maps found.", mapList.size()));
RawTextPart rawText = new RawText("");
rawText = addMap(rawText, mapList.get(0));
for (int i = 1, c = mapList.size(); i < c; i++) {
rawText = rawText.then(", ").color(ChatColor.GRAY);
rawText = addMap(rawText, mapList.get(i));
}
RawMessage.send(playerSender(), rawText.build());
}
private RawTextPart<?> addMap(RawTextPart<?> rawText, ImageMap map) {
final String size = map.getType() == ImageMap.Type.SINGLE ? "1 × 1" :
((PosterMap) map).getColumnCount() + " × " + ((PosterMap) map).getRowCount();
return rawText
.then(map.getId())
.color(ChatColor.WHITE)
.command(GetCommand.class, map.getId())
.hover(new RawText()
.then(map.getName()).style(ChatColor.BOLD, ChatColor.GREEN).then("\n")
.then(map.getId() + ", " + size).color(ChatColor.GRAY).then("\n\n")
.then(I.t("{white}Click{gray} to get this map"))
);
}
@Override
public boolean canExecute(CommandSender sender) {
return Permissions.LISTOTHER.grantedTo(sender);
}
}

View File

@ -57,6 +57,21 @@ import org.bukkit.entity.Player;
@CommandInfo(name = "new", usageParameters = "<URL> [resize]")
public class NewCommand extends IoMCommand {
private ImageUtils.ScalingType resizeMode() throws CommandException {
switch (args[1]) {
case "resize":
return ImageUtils.ScalingType.CONTAINED;
case "resize-stretched":
return ImageUtils.ScalingType.STRETCHED;
case "resize-covered":
return ImageUtils.ScalingType.COVERED;
default:
throwInvalidArgument(I.t("Invalid Stretching mode."));
return ImageUtils.ScalingType.NONE;
}
}
@Override
protected void run() throws CommandException {
final Player player = playerSender();
@ -81,21 +96,7 @@ public class NewCommand extends IoMCommand {
width = Integer.parseInt(args[2]);
height = Integer.parseInt(args[3]);
}
switch (args[1]) {
case "resize":
scaling = ImageUtils.ScalingType.CONTAINED;
break;
case "resize-stretched":
scaling = ImageUtils.ScalingType.STRETCHED;
break;
case "resize-covered":
scaling = ImageUtils.ScalingType.COVERED;
break;
default:
throwInvalidArgument(I.t("Invalid Stretching mode."));
break;
}
scaling = resizeMode();
}
try {
ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("Rendering..."));

View File

@ -21,27 +21,33 @@ package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.CommandSender;
@CommandInfo(name = "rename", usageParameters = "<original map name> <new map name>")
public class RenameCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
if (args.length != 4) {
ArrayList<String> argList = getArgs();
if (argList.size() != 2) {
warning(I.t("Not enough or too many arguments! Usage: /maptool rename <map name> <new map name>"));
return;
}
//if(args.length == 2)
//{
ImageMap map = getMapFromArgs();
map.rename(args[2]);
// } else {
// info(I.t("Not enough or too many arguments"));
// }
ImageMap map = MapManager.getMap(playerSender().getUniqueId(), argList.get(0));
if (map == null) {
error(I.t("This map does not exist."));
return;
}
map.rename(argList.get(1));
}
@Override

View File

@ -36,6 +36,7 @@
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.image.ImageRendererExecutor;
@ -51,28 +52,97 @@ import fr.zcraft.quartzlib.tools.text.ActionBar;
import fr.zcraft.quartzlib.tools.text.MessageSender;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.ArrayList;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "update", usageParameters = "<new url> [stretched|covered] \"<map name to update>\"")
@CommandInfo(name = "update", usageParameters = "[player name]:<map name> <new url> [stretched|covered] ")
public class UpdateCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
final Player player = playerSender();
ImageUtils.ScalingType scaling;
URL url;
if (args.length < 1) {
throwInvalidArgument(I.t("You must give an URL and a map name to update."));
//TODO fix the issue where to many quick usage of offlineNameFetch will return null
ArrayList<String> arguments = getArgs();
String warningMsg;
if (arguments.size() > 4) {
warningMsg = "Too many parameters!"
+ " Usage: /maptool update [player name]:<map name> <new url> [stretched|covered]";
warning(I.t(warningMsg));
return;
}
if (args.length < 2) {
throwInvalidArgument(I.t("You must give a map name to update."));
if (arguments.size() < 2) {
warningMsg =
"Too few parameters! Usage: /maptool update [player name]:<map name> <new url> [stretched|covered]";
warning(I.t(warningMsg));
return;
}
final String playerName;
final String mapName;
final String url;
final String resize;
final Player playerSender;
Player playerSender1;
try {
playerSender1 = playerSender();
} catch (CommandException ignored) {
if (arguments.size() == 2) {
throwInvalidArgument(
I.t("Usage: /maptool update [player name]:<map name> <new url> [stretched|covered]"));
}
playerSender1 = null;
}
playerSender = playerSender1;
//Sent by a non player and not enough arguments
if (arguments.size() == 2 && playerSender == null) {
throwInvalidArgument("Usage: /maptool update [player name]:<map name> <new url> [stretched|covered]");
return;
}
switch (args[1]) {
if (arguments.size() == 2) {
resize = "";
playerName = playerSender.getName();
mapName = arguments.get(0);
url = arguments.get(1);
} else {
if (arguments.size() == 4) {
if (!Permissions.UPDATEOTHER.grantedTo(sender)) {
throwNotAuthorized();
return;
}
playerName = arguments.get(0);
mapName = arguments.get(1);
url = arguments.get(2);
resize = arguments.get(3);
} else {
if (arguments.size() == 3) {
if (arguments.get(2).equals("covered") || arguments.get(2).equals("stretched")) {
playerName = playerSender.getName();
mapName = arguments.get(0);
url = arguments.get(1);
resize = arguments.get(2);
} else {
if (!Permissions.UPDATEOTHER.grantedTo(sender)) {
throwNotAuthorized();
return;
}
playerName = arguments.get(0);
mapName = arguments.get(1);
url = arguments.get(2);
resize = "";
}
} else {
resize = "";
playerName = "";
url = "";
mapName = "";
}
}
}
final ImageUtils.ScalingType scaling;
switch (resize) {
case "stretched":
scaling = ImageUtils.ScalingType.STRETCHED;
@ -83,50 +153,72 @@ public class UpdateCommand extends IoMCommand {
default:
scaling = ImageUtils.ScalingType.CONTAINED;
}
ImageMap map;
if (scaling.equals(ImageUtils.ScalingType.CONTAINED)) {
map = getMapFromArgs(player, 1);
} else {
map = getMapFromArgs(player, 2);
}
try {
url = new URL(args[0]);
MapManager.load();
Integer[] size = {1, 1};
if (map.getType() == ImageMap.Type.POSTER) {
size = map.getSize(new HashMap<String, Object>(), map.getUserUUID(), map.getId());
//TODO passer en static
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
if (uuid == null) {
warning(sender, I.t("The player {0} does not exist.", playerName));
return;
}
//assert size != null;
int width = size[0];
int height = size[1];
ImageMap map = MapManager.getMap(uuid, mapName);
if (map == null) {
warning(sender, I.t("This map does not exist."));
return;
}
URL url1;
try {
ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("Updating..."));
ImageRendererExecutor
.update(url, scaling, player.getUniqueId(), map, width, height, new WorkerCallback<ImageMap>() {
@Override
public void finished(ImageMap result) {
ActionBar.removeMessage(player);
MessageSender.sendActionBarMessage(player,
ChatColor.DARK_GREEN + I.t("The map was updated using the new image!"));
}
url1 = new URL(url);
//TODO replace by a check of the load status.(if not loaded load the mapmanager)
MapManager.load(false);//we don't want to spam the console each time we reload the mapManager
@Override
public void errored(Throwable exception) {
player.sendMessage(I.t("{ce}Map rendering failed: {0}", exception.getMessage()));
Integer[] size = {1, 1};
if (map.getType() == ImageMap.Type.POSTER) {
size = map.getSize(map.getUserUUID(), map.getId());
}
PluginLogger.warning("Rendering from {0} failed: {1}: {2}",
player.getName(),
exception.getClass().getCanonicalName(),
exception.getMessage());
}
});
} finally {
ActionBar.removeMessage(player);
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 ex) {
warning(sender, I.t("Invalid URL."));
}
} catch (MalformedURLException ex) {
throwInvalidArgument(I.t("Invalid URL."));
}
});
}
@Override

View File

@ -1,136 +0,0 @@
/*
* Copyright or © or Copr. Moribus (2013)
* Copyright or © or Copr. ProkopyL <prokopylmc@gmail.com> (2015)
* Copyright or © or Copr. Amaury Carrade <amaury@carrade.eu> (2016 2020)
* Copyright or © or Copr. Vlammar <valentin.jabre@gmail.com> (2019 2020)
*
* This software is a computer program whose purpose is to allow insertion of
* custom images in a Minecraft world.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.image.ImageRendererExecutor;
import fr.moribus.imageonmap.image.ImageUtils;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.zcraft.quartzlib.components.commands.CommandException;
import fr.zcraft.quartzlib.components.commands.CommandInfo;
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.worker.WorkerCallback;
import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.quartzlib.tools.text.ActionBar;
import fr.zcraft.quartzlib.tools.text.MessageSender;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandInfo(name = "update", usageParameters = "<new url> [stretched|covered] \"<map name to update>\"")
public class UpdateOtherCommand extends IoMCommand {
@Override
protected void run() throws CommandException {
//TODO separer les deux update(update et update other)
final Player player = playerSender();
ImageUtils.ScalingType scaling;
URL url;
if (args.length < 1) {
throwInvalidArgument(I.t("You must give an URL and a map name to update."));
}
if (args.length < 2) {
throwInvalidArgument(I.t("You must give a map name to update."));
}
switch (args[1]) {
case "stretched":
scaling = ImageUtils.ScalingType.STRETCHED;
break;
case "covered":
scaling = ImageUtils.ScalingType.COVERED;
break;
default:
scaling = ImageUtils.ScalingType.CONTAINED;
}
ImageMap map;
if (scaling.equals(ImageUtils.ScalingType.CONTAINED)) {
map = getMapFromArgs(player, 1);
} else {
map = getMapFromArgs(player, 2);
}
try {
url = new URL(args[0]);
MapManager.load();
Integer[] size = {1, 1};
if (map.getType() == ImageMap.Type.POSTER) {
size = map.getSize(new HashMap<String, Object>(), map.getUserUUID(), map.getId());
}
int width = size[0];
int height = size[1];
try {
ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("Updating..."));
ImageRendererExecutor
.update(url, scaling, player.getUniqueId(), map, width, height, new WorkerCallback<ImageMap>() {
@Override
public void finished(ImageMap result) {
ActionBar.removeMessage(player);
MessageSender.sendActionBarMessage(player,
ChatColor.DARK_GREEN + I.t("The map was updated using the new image!"));
}
@Override
public void errored(Throwable exception) {
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());
}
});
} finally {
ActionBar.removeMessage(player);
}
} catch (MalformedURLException ex) {
throwInvalidArgument(I.t("Invalid URL."));
}
}
@Override
public boolean canExecute(CommandSender sender) {
return Permissions.UPDATEOTHER.grantedTo(sender);
}
}

View File

@ -123,9 +123,8 @@ public class ConfirmDeleteMapGui extends ActionGui {
.lore(I.t(getPlayerLocale(), "{gray}Name: {white}{0}", mapToDelete.getName()))
.lore(I.t(getPlayerLocale(), "{gray}Map ID: {white}{0}", mapToDelete.getId()))
.lore(I.t(getPlayerLocale(), "{gray}Maps inside: {white}{0}", mapToDelete.getMapsIDs().length))
.hideAllAttributes()
);
//.hideAllAttributes()
/* ** Buttons ** */

View File

@ -51,7 +51,6 @@ import fr.zcraft.quartzlib.tools.items.ItemStackBuilder;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta;
@ -60,7 +59,7 @@ public class MapListGui extends ExplorerGui<ImageMap> {
private OfflinePlayer offplayer;
private String name;
public MapListGui(Player sender) {
public MapListGui(OfflinePlayer sender) {
this.offplayer = sender;
this.name = sender.getName();
}
@ -225,7 +224,7 @@ public class MapListGui extends ExplorerGui<ImageMap> {
mapPartLeft));
}
//statistics.hideAllAttributes();
statistics.hideAllAttributes();
action("", getSize() - 5, statistics);
}

View File

@ -108,7 +108,7 @@ public abstract class ImageMap implements ConfigurationSerializable {
}
}
public static Integer[] getSize(Map<String, Object> map, UUID playerUUID, String id) {
public static Integer[] getSize(UUID playerUUID, String id) {
ConfigurationSection section =
MapManager.getPlayerMapStore(playerUUID).getToolConfig().getConfigurationSection("PlayerMapStore");

View File

@ -260,7 +260,13 @@ public abstract class MapManager {
}
}
//Silent load
public static void load() {
load(true);
}
//Loading
public static void load(boolean verbose) {
int loadedFilesCount = 0;
for (File file : ImageOnMap.getPlugin().getMapsDirectory().listFiles()) {
UUID uuid = getUUIDFromFile(file);
@ -271,7 +277,9 @@ public abstract class MapManager {
++loadedFilesCount;
}
PluginLogger.info("Loaded {0} player map files.", loadedFilesCount);
if (verbose) {
PluginLogger.info("Loaded {0} player map files.", loadedFilesCount);
}
}
public static void save() {

View File

@ -165,12 +165,12 @@ public class MapItemManager implements Listener {
if (goldTitle) {
mapItem = new ItemStackBuilder(Material.FILLED_MAP)
.title(ChatColor.GOLD, text)
//.hideAllAttributes()
.hideAllAttributes()
.item();
} else {
mapItem = new ItemStackBuilder(Material.FILLED_MAP)
.title(text)
//.hideAllAttributes()
.hideAllAttributes()
.item();
}
final MapMeta meta = (MapMeta) mapItem.getItemMeta();
@ -312,7 +312,7 @@ public class MapItemManager implements Listener {
frame.setItem(new ItemStackBuilder(item)
.title(getMapTitle(item))
//.hideAllAttributes()
.hideAllAttributes()
.item());
}

View File

@ -95,7 +95,7 @@ public abstract class SplatterMapManager {
.loreLine()
.longLore(ChatColor.GRAY
+ I.t("Shift-click one of the placed maps to remove the whole poster in one shot."), 40)
//.hideAllAttributes()
.hideAllAttributes()
.craftItem();
final MapMeta meta = (MapMeta) splatter.getItemMeta();
@ -169,7 +169,7 @@ public abstract class SplatterMapManager {
}
/**
* Return true if it is a platter map
* Return true if it is a splatter map
*
* @param itemStack The item to check.
* @return True if is a splatter map
@ -182,7 +182,13 @@ public abstract class SplatterMapManager {
}
//TODO doc a faire
/**
* Return true if it has a specified splatter map
*
* @param player The player to check.
* @param map The map to check.
* @return True if the player has this map
*/
public static boolean hasSplatterMap(Player player, PosterMap map) {
Inventory playerInventory = player.getInventory();

View File

@ -10,5 +10,8 @@ list: Lists all the map you currently have.
listother: list all the map of another player.
explore: Opens a GUI to see and manage your maps.
exploreother: Opens a GUI to see and manage another player maps.
give: Give a specified player a map
rename: Rename an ImageOnMap
update: Update a specified ImageOnMap
migrate: Lauches the migration process from V2.7 to V3.x.
help : Use help for more information about a command.

View File

@ -12,9 +12,9 @@ commands:
description: Manage maps
maps:
description: Manage maps through a GUI
mapgive:
givemap:
description: give a map to a player from a player map store, by default take from the player that make the command
usage: /<command> player_to map_name [player_from]
usage: /<command> [player_from] player_to map_name
permissions:
imageonmap.*:
@ -24,11 +24,11 @@ permissions:
imageonmap.userender: true
imageonmap.new: true
imageonmap.list: true
imageonmap.listother: true
imageonmap.listother: false
imageonmap.get: true
imageonmap.getother: true
imageonmap.getother: false
imageonmap.explore: true
imageonmap.exploreother: true
imageonmap.exploreother: false
imageonmap.rename: true
imageonmap.removesplattermap: true
imageonmap.delete: true
@ -52,7 +52,7 @@ permissions:
imageonmap.listother:
description: "Allows you to list the images a player have rendered."
default: false
default: op
imageonmap.get:
description: "Allows you to get a new map among the ones you already rendered, and related commands (/maptool getremaining)."
@ -60,7 +60,7 @@ permissions:
imageonmap.getother:
description: "Allows you to get a new map among the ones a player have already rendered."
default: false
default: op
imageonmap.explore:
description: "Allows you to open a GUI with all your maps."
@ -68,7 +68,7 @@ permissions:
imageonmap.exploreother:
description: "Allows you to open a GUI with all of the player maps."
default: false
default: op
imageonmap.rename:
description: "Allows you to rename a map you rendered in the past."
@ -84,7 +84,7 @@ permissions:
imageonmap.deleteother:
description: "Allows you to delete a map a player rendered in the past."
default: false
default: op
imageonmap.removesplattermap:
description: "Allows you to remove a splatter map from a wall by sneaking and breaking a map."