From f0d1d33bb854ce2a026620afb86c71190c2436ea Mon Sep 17 00:00:00 2001 From: Vlammar Date: Thu, 23 Jul 2020 11:06:53 +0200 Subject: [PATCH] add give command --- .../fr/moribus/imageonmap/ImageOnMap.java | 3 +- .../fr/moribus/imageonmap/Permissions.java | 3 +- .../commands/maptool/GiveCommand.java | 98 +++++++++++++++++++ src/main/resources/plugin.yml | 5 + 4 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 src/main/java/fr/moribus/imageonmap/commands/maptool/GiveCommand.java diff --git a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java index 2c1361d..f55d4fd 100644 --- a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java +++ b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java @@ -119,7 +119,8 @@ public final class ImageOnMap extends ZPlugin DeleteCommand.class, GetRemainingCommand.class, ExploreCommand.class, - MigrateCommand.class + MigrateCommand.class, + GiveCommand.class ); Commands.registerShortcut("maptool", NewCommand.class, "tomap"); diff --git a/src/main/java/fr/moribus/imageonmap/Permissions.java b/src/main/java/fr/moribus/imageonmap/Permissions.java index 6667243..8065ee2 100644 --- a/src/main/java/fr/moribus/imageonmap/Permissions.java +++ b/src/main/java/fr/moribus/imageonmap/Permissions.java @@ -46,7 +46,8 @@ public enum Permissions RENAME("imageonmap.rename"), DELETE("imageonmap.delete"), ADMINISTRATIVE("imageonmap.administrative"), - BYPASS_SIZE("imageonmap.bypasssize") + BYPASS_SIZE("imageonmap.bypasssize"), + GIVE("imageonmap.give") ; diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/GiveCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/GiveCommand.java new file mode 100644 index 0000000..f993a17 --- /dev/null +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/GiveCommand.java @@ -0,0 +1,98 @@ +/* + * 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.zlib.components.commands.CommandException; +import fr.zcraft.zlib.components.commands.CommandInfo; +import fr.zcraft.zlib.components.i18n.I; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + + +@CommandInfo (name = "give", usageParameters = " or ") +public class GiveCommand extends IoMCommand +{ + @Override + protected void run() throws CommandException + { + if(args.length < 2) throwInvalidArgument(I.t("You must give a valid player name and a map name.")); + + final Player p= Bukkit.getPlayer(args[0]); + + ImageMap map; + //TODO does not support map name with space + Player player=null; + if(args.length<4) { + if (args.length == 2) { + player = playerSender(); + } + if (args.length == 3) { + player = Bukkit.getPlayer(args[2]); + if(player==null){ + try{ + playerSender().sendMessage(I.t("Player map store not found")); + } + catch (Exception e){ + + } + return; + } + } + if (p == null) { + player.sendMessage(I.t("Player not found")); + return; + } + map = MapManager.getMap(player.getUniqueId(), args[1]); + if (map == null) { + player.sendMessage(I.t("Map not found")); + return; + } + map.give(p); + } + } + + @Override + public boolean canExecute(CommandSender sender) + { + return Permissions.GIVE.grantedTo(sender); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ef82c43..69db22f 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -25,6 +25,7 @@ permissions: imageonmap.rename: true imageonmap.delete: true imageonmap.bypasssize: false + imageonmap.give: false imageonmap.userender: description: "Allows you to use /tomap and related commands (/maptool getremaing). Alias of imageonmap.new." @@ -54,6 +55,10 @@ permissions: description: "Allows you to delete a map you rendered in the past." default: true + imageonmap.give: + description: "Allows you to give a map to a specified player." + default: op + imageonmap.administrative: description: "Allows you to perform administrative tasks (like /maptool migrate)." default: op