From 50008de052e6c5fd095410efffca507c9115cc86 Mon Sep 17 00:00:00 2001 From: Vlammar Date: Sat, 12 Dec 2020 23:52:48 +0100 Subject: [PATCH] Merged get and getother --- .../fr/moribus/imageonmap/ImageOnMap.java | 2 - .../commands/maptool/GetCommand.java | 47 ++++++++- .../commands/maptool/GetOtherCommand.java | 99 ------------------- .../commands/maptool/ListCommand.java | 8 +- 4 files changed, 49 insertions(+), 107 deletions(-) delete mode 100644 src/main/java/fr/moribus/imageonmap/commands/maptool/GetOtherCommand.java diff --git a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java index 9817b16..562e4c8 100644 --- a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java +++ b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java @@ -42,7 +42,6 @@ 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; @@ -133,7 +132,6 @@ public final class ImageOnMap extends QuartzPlugin { NewCommand.class, ListCommand.class, GetCommand.class, - GetOtherCommand.class, RenameCommand.class, DeleteCommand.class, DeleteOtherCommand.class, diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/GetCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/GetCommand.java index 4876853..45d1736 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/GetCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/GetCommand.java @@ -36,11 +36,15 @@ 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; @@ -49,11 +53,46 @@ import org.bukkit.entity.Player; 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 arguments = getArgs(); + if (arguments.size() > 2) { + warning(I.t("Too many parameters! Usage: /maptool getother [playername] ")); + return; } + + final String playerName; + final String mapName; + final Player sender = playerSender(); + if (arguments.size() == 2) { + if (!Permissions.GETOTHER.grantedTo(sender)) { + info(sender, I.t("You can't use this command")); + 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) { + info(sender, I.t("The player {0} does not exist.", playerName)); + return; + } + ImageMap map = MapManager.getMap(uuid, mapName); + + if (map == null) { + info(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 diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/GetOtherCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/GetOtherCommand.java deleted file mode 100644 index 39581ce..0000000 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/GetOtherCommand.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright or © or Copr. Moribus (2013) - * Copyright or © or Copr. ProkopyL (2015) - * Copyright or © or Copr. Amaury Carrade (2016 – 2020) - * Copyright or © or Copr. Vlammar (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 = " ") -public class GetOtherCommand extends IoMCommand { - - @Override - protected void run() throws CommandException { - if (args.length < 2) { - warning(I.t("Not enough parameters! Usage: /maptool getother ")); - 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); - } -} diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java index 6f305f8..7823d5e 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java @@ -77,11 +77,15 @@ public class ListCommand extends IoMCommand { } final Player sender = playerSender(); + //TODO passer en static ImageOnMap.getPlugin().getCommandWorker().OfflineNameFetch(playerName, uuid -> { List mapList = MapManager.getMapList(uuid); - - if (uuid == null || mapList.isEmpty()) { + if (uuid == null) { + info(sender, I.t("Player {} not found.", playerName)); + return; + } + if (mapList.isEmpty()) { info(sender, I.t("No map found.")); return; }