From fcc48cb4024625c11c507982bb20cbbbd2fe53d9 Mon Sep 17 00:00:00 2001 From: Vlammar Date: Thu, 27 Aug 2020 01:32:04 +0200 Subject: [PATCH] fixed various issues with the admin command, refactored some of the code and added an exploredother command --- .../fr/moribus/imageonmap/ImageOnMap.java | 5 +- .../commands/maptool/DeleteCommand.java | 28 ++++--- .../commands/maptool/DeleteOtherCommand.java | 72 ++++++++++------ .../commands/maptool/ExploreCommand.java | 2 +- .../commands/maptool/ExploreOtherCommand.java | 83 +++++++++++++++++++ .../commands/maptool/GetOtherCommand.java | 74 +++++++++++------ .../commands/maptool/ListOtherCommand.java | 74 ++++++++++------- .../imageonmap/gui/ConfirmDeleteMapGui.java | 3 +- .../moribus/imageonmap/gui/MapDetailGui.java | 21 +++-- .../fr/moribus/imageonmap/gui/MapListGui.java | 46 +++++++--- src/main/resources/help/maptool.txt | 1 + src/main/resources/plugin.yml | 32 +++++-- 12 files changed, 322 insertions(+), 119 deletions(-) create mode 100644 src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreOtherCommand.java diff --git a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java index 38cf7c7..608e980 100644 --- a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java +++ b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java @@ -118,13 +118,14 @@ public final class ImageOnMap extends ZPlugin "maptool", NewCommand.class, ListCommand.class, + ListOtherCommand.class, GetCommand.class, GetOtherCommand.class, - ListOtherCommand.class, - DeleteOtherCommand.class, DeleteCommand.class, + DeleteOtherCommand.class, GetRemainingCommand.class, ExploreCommand.class, + ExploreOtherCommand.class, MigrateCommand.class ); diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteCommand.java index a2516f1..2041d60 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteCommand.java @@ -57,6 +57,20 @@ import java.util.List; @WithFlags ({"confirm"}) public class DeleteCommand extends IoMCommand { + + private static RawText deleteMsg(Class klass,ImageMap map){ + return new RawText(I.t("You are going to delete") + " ") + .then(map.getId()) + .color(ChatColor.GOLD) + .then(". " + I.t("Are you sure ? ")) + .color(ChatColor.WHITE) + .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") + .build(); + } + @Override protected void run() throws CommandException { @@ -64,17 +78,7 @@ public class DeleteCommand extends IoMCommand if (!hasFlag("confirm")) { - RawText msg = new RawText(I.t("You are going to delete") + " ") - .then(map.getId()) - .color(ChatColor.GOLD) - .then(". " + I.t("Are you sure ? ")) - .color(ChatColor.WHITE) - .then(I.t("[Confirm]")) - .color(ChatColor.GREEN) - .hover(new RawText(I.t("{red}This map will be deleted {bold}forever{red}!"))) - .command(getClass(), map.getId(), "--confirm") - .build(); - + RawText msg = deleteMsg(getClass(),map); send(msg); } else @@ -89,7 +93,7 @@ public class DeleteCommand extends IoMCommand } catch (MapManagerException ex) { - PluginLogger.warning("A non-existent map was requested to be deleted", ex); + PluginLogger.warning(I.t("A non-existent map was requested to be deleted", ex)); warning(I.t("This map does not exist.")); } } diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteOtherCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteOtherCommand.java index 91d7680..dfcf537 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteOtherCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/DeleteOtherCommand.java @@ -1,19 +1,37 @@ /* - * Copyright (C) 2013 Moribus - * Copyright (C) 2015 ProkopyL + * 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 program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This software is a computer program whose purpose is to allow insertion of + * custom images in a Minecraft world. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * 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". * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * 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; @@ -28,8 +46,8 @@ import fr.zcraft.zlib.components.commands.CommandInfo; import fr.zcraft.zlib.components.commands.WithFlags; import fr.zcraft.zlib.components.i18n.I; import fr.zcraft.zlib.tools.PluginLogger; - import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -44,12 +62,16 @@ public class DeleteOtherCommand extends IoMCommand @Override protected void run() throws CommandException { - if(!playerSender().hasPermission("imageonmap.delete.other")) { + /*if(!playerSender().hasPermission("imageonmap.delete.other")) { warning(I.t("You do not have permission for this command. (imageonmap.delete.other)")); return; - } - if(args.length < 2) warning(I.t("Not enough parameters! Usage: /maptool deleteother ")); - + }*/ + if(args.length < 2) { + warning(I.t("Not enough parameters! Usage: /maptool deleteother ")); + return; + } + + Player player = null; UUID uuid = null; OfflinePlayer op = null; @@ -60,23 +82,24 @@ public class DeleteOtherCommand extends IoMCommand else warning(I.t("We've never seen that player before!")); } else uuid = player.getUniqueId(); - String mapName = ""; - mapName = args[1]; - if(args.length > 2) for(int i = 2; i < args.length; i++) mapName += (" " + args[i - 1]); - - ImageMap map = MapManager.getMap(uuid, mapName); + if(player==null){ + warning(I.t("Player not found")); + return; + } + ImageMap map = getMapFromArgs(player, 1, true); + //ImageMap map = MapManager.getMap(uuid, mapName); if(player != null) MapManager.clear(player.getInventory(), map); try { MapManager.deleteMap(map); - getPlayer().sendMessage(I.t("{gray}Map successfully deleted.")); + info(I.t("{gray}Map successfully deleted.")); } catch (MapManagerException ex) { PluginLogger.warning(I.t("A non-existent map was requested to be deleted", ex)); - getPlayer().sendMessage(ChatColor.RED+(I.t("This map does not exist."))); + warning(ChatColor.RED+(I.t("This map does not exist."))); } } @@ -89,6 +112,7 @@ public class DeleteOtherCommand extends IoMCommand return null; } + @Override public boolean canExecute(CommandSender sender) { diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreCommand.java index d4bac06..cd3f96f 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreCommand.java @@ -52,7 +52,7 @@ public class ExploreCommand extends IoMCommand @Override protected void run() throws CommandException { - Gui.open(playerSender(), new MapListGui()); + Gui.open(playerSender(), new MapListGui(playerSender())); } @Override diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreOtherCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreOtherCommand.java new file mode 100644 index 0000000..8e8af95 --- /dev/null +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreOtherCommand.java @@ -0,0 +1,83 @@ +/* + * 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.gui.MapListGui; +import fr.zcraft.zlib.components.commands.CommandException; +import fr.zcraft.zlib.components.commands.CommandInfo; +import fr.zcraft.zlib.components.gui.Gui; +import fr.zcraft.zlib.components.i18n.I; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; + +import java.io.IOException; + + +@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 ")); + return; + } + + try{ + OfflinePlayer player=getOfflinePlayerParameter(0); + String name=args[0]; + if(player!=null) + Gui.open(playerSender(), new MapListGui(player,name)); + } + catch (InterruptedException | IOException e){ + warning(I.t("Can't find player")); + return; + } + + + } + + @Override + public boolean canExecute(CommandSender sender) + { + return Permissions.LISTOTHER.grantedTo(sender); + } +} diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/GetOtherCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/GetOtherCommand.java index d8529d5..ba18870 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/GetOtherCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/GetOtherCommand.java @@ -1,31 +1,42 @@ /* - * Copyright (C) 2013 Moribus - * Copyright (C) 2015 ProkopyL + * 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 program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This software is a computer program whose purpose is to allow insertion of + * custom images in a Minecraft world. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * 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". * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * 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 java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import fr.moribus.imageonmap.Permissions; import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.map.ImageMap; @@ -33,29 +44,36 @@ 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.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.UUID; @CommandInfo (name = "getother", usageParameters = " ") public class GetOtherCommand extends IoMCommand { - @SuppressWarnings("deprecation") + @Override protected void run() throws CommandException { - if(args.length < 2) warning(I.t("Not enough parameters! Usage: /maptool getother ")); - //Deny those who do not have permission. - if(!playerSender().hasPermission("imageonmap.get.other")) { - warning(I.t("You do not have permission for this command. (imageonmap.get.other)")); + + 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(); @@ -69,7 +87,11 @@ public class GetOtherCommand extends IoMCommand } } map = MapManager.getMap(uuid, mapName); - map.give(playerSender()); + if(map!=null) + map.give(playerSender()); + else{ + warning(I.t("Unknown map {0}",mapName)); + } return; } @Override diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/ListOtherCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/ListOtherCommand.java index 89540e4..52f0091 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/ListOtherCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/ListOtherCommand.java @@ -1,34 +1,42 @@ /* - * Copyright (C) 2013 Moribus - * Copyright (C) 2015 ProkopyL + * 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 program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * This software is a computer program whose purpose is to allow insertion of + * custom images in a Minecraft world. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * 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". * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * 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 java.util.List; -import java.util.UUID; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - import fr.moribus.imageonmap.Permissions; import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.map.ImageMap; @@ -39,8 +47,15 @@ import fr.zcraft.zlib.components.commands.CommandInfo; import fr.zcraft.zlib.components.i18n.I; import fr.zcraft.zlib.components.rawtext.RawText; import fr.zcraft.zlib.components.rawtext.RawTextPart; -import fr.zcraft.zlib.tools.items.ItemStackBuilder; import fr.zcraft.zlib.tools.text.RawMessage; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.UUID; @CommandInfo (name = "listother", usageParameters = "") @@ -49,11 +64,12 @@ public class ListOtherCommand extends IoMCommand @Override protected void run() throws CommandException { - if(args.length < 1) warning(I.t("Not enough parameters! Usage: /maptool listother ")); - if(!playerSender().hasPermission("imageonmap.list.other")) { - warning(I.t("You do not have permission for this command. (imageonmap.list.other)")); - return; + + if(args.length < 1){ + warning(I.t("Not enough parameters! Usage: /maptool listother ")); + return; } + Player player = null; UUID uuid = null; @@ -65,7 +81,6 @@ public class ListOtherCommand extends IoMCommand } else { warning(I.t("We've never seen that player before!")); - } } else{ @@ -77,8 +92,9 @@ public class ListOtherCommand extends IoMCommand mapList = MapManager.getMapList(uuid); } catch(Exception e){ - + return; } + if(mapList.isEmpty()) { info(I.t("No map found.")); diff --git a/src/main/java/fr/moribus/imageonmap/gui/ConfirmDeleteMapGui.java b/src/main/java/fr/moribus/imageonmap/gui/ConfirmDeleteMapGui.java index b60768d..1f81604 100644 --- a/src/main/java/fr/moribus/imageonmap/gui/ConfirmDeleteMapGui.java +++ b/src/main/java/fr/moribus/imageonmap/gui/ConfirmDeleteMapGui.java @@ -168,12 +168,13 @@ public class ConfirmDeleteMapGui extends ActionGui @GuiAction ("cancel") protected void cancel() { - close(); + close(); } @GuiAction ("delete") protected void delete() { + // Does the player still have the permission to delete a map? if (!Permissions.DELETE.grantedTo(getPlayer())) { diff --git a/src/main/java/fr/moribus/imageonmap/gui/MapDetailGui.java b/src/main/java/fr/moribus/imageonmap/gui/MapDetailGui.java index 9717771..f08395a 100644 --- a/src/main/java/fr/moribus/imageonmap/gui/MapDetailGui.java +++ b/src/main/java/fr/moribus/imageonmap/gui/MapDetailGui.java @@ -47,21 +47,25 @@ import fr.zcraft.zlib.components.gui.GuiAction; import fr.zcraft.zlib.components.gui.PromptGui; import fr.zcraft.zlib.components.i18n.I; import fr.zcraft.zlib.tools.Callback; +import fr.zcraft.zlib.tools.PluginLogger; import fr.zcraft.zlib.tools.items.ItemStackBuilder; import org.apache.commons.lang.ArrayUtils; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.inventory.ItemStack; public class MapDetailGui extends ExplorerGui { private final ImageMap map; + private OfflinePlayer p; + private String name; - public MapDetailGui(ImageMap map) - { - this.map = map; + public MapDetailGui(ImageMap map, OfflinePlayer p, String name){ + this.map=map; + this.p=p; + this.name=name; } - @Override protected ItemStack getViewItem(int x, int y) { @@ -136,7 +140,12 @@ public class MapDetailGui extends ExplorerGui protected void onUpdate() { /// Title of the map details GUI - setTitle(I.t(getPlayerLocale(), "Your maps » {black}{0}", map.getName())); + if(p.getUniqueId().equals(getPlayer().getUniqueId())) { + setTitle(I.t(getPlayerLocale(), "Your maps » {black}{0}", map.getName())); + } + else{ + setTitle(I.t(getPlayerLocale(), "{1}'s maps » {black}{0}", map.getName(),name)); + } setKeepHorizontalScrollingSpace(true); if (map instanceof PosterMap) @@ -236,13 +245,13 @@ public class MapDetailGui extends ExplorerGui @GuiAction ("delete") public void delete() { + PluginLogger.info("delete"); if (!Permissions.DELETE.grantedTo(getPlayer())) { I.sendT(getPlayer(), "{ce}You are no longer allowed to do that."); update(); return; } - Gui.open(getPlayer(), new ConfirmDeleteMapGui(map), this); } diff --git a/src/main/java/fr/moribus/imageonmap/gui/MapListGui.java b/src/main/java/fr/moribus/imageonmap/gui/MapListGui.java index 40f38d9..4bf7644 100644 --- a/src/main/java/fr/moribus/imageonmap/gui/MapListGui.java +++ b/src/main/java/fr/moribus/imageonmap/gui/MapListGui.java @@ -49,12 +49,25 @@ import fr.zcraft.zlib.components.i18n.I; import fr.zcraft.zlib.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; public class MapListGui extends ExplorerGui { + private OfflinePlayer p; + private String name; + public MapListGui(Player sender){ + this.p=sender; + this.name=sender.getName(); + } + public MapListGui( OfflinePlayer p,String name){ + this.p=p; + this.name=name; + } + @Override protected ItemStack getViewItem(ImageMap map) { @@ -106,23 +119,29 @@ public class MapListGui extends ExplorerGui @Override protected ItemStack getEmptyViewItem() { - ItemStackBuilder builder = new ItemStackBuilder(Material.BARRIER) - .title(I.tl(getPlayerLocale(), "{red}You don't have any map.")); + ItemStackBuilder builder = new ItemStackBuilder(Material.BARRIER); + if(p.getUniqueId().equals(getPlayer().getUniqueId())) { - if (Permissions.NEW.grantedTo(getPlayer())) - builder.longLore(I.tl(getPlayerLocale(), "{gray}Get started by creating a new one using {white}/tomap [resize]{gray}!")); - else - builder.longLore(I.tl(getPlayerLocale(), "{gray}Unfortunately, you are not allowed to create one.")); + builder.title(I.tl(getPlayerLocale(), "{red}You don't have any map.")); + if (Permissions.NEW.grantedTo(getPlayer())) + builder.longLore(I.tl(getPlayerLocale(), "{gray}Get started by creating a new one using {white}/tomap [resize]{gray}!")); + else + builder.longLore(I.tl(getPlayerLocale(), "{gray}Unfortunately, you are not allowed to create one.")); + } + else{ + builder.title(I.tl(getPlayerLocale(), "{red}{0} doesn't have any map.",name)); + } return builder.item(); } @Override protected void onRightClick(ImageMap data) { - Gui.open(getPlayer(), new MapDetailGui(data), this); + Gui.open(getPlayer(), new MapDetailGui(data,getPlayer(),name), this); } + @Override protected ItemStack getPickedUpItem(ImageMap map) { @@ -151,19 +170,22 @@ public class MapListGui extends ExplorerGui @Override protected void onUpdate() { - ImageMap[] maps = MapManager.getMaps(getPlayer().getUniqueId()); + ImageMap[] maps = MapManager.getMaps(p.getUniqueId()); setData(maps); /// The maps list GUI title - setTitle(I.tl(getPlayerLocale(), "{black}Your maps {reset}({0})", maps.length)); + //Equal if the person who send the command is the owner of the mapList + if(p.getUniqueId().equals(getPlayer().getUniqueId())) + setTitle(I.tl(getPlayerLocale(), "{black}Your maps {reset}({0})", maps.length)); + else + setTitle(I.tl(getPlayerLocale(), "{black}{1}'s maps {reset}({0})", maps.length, name )); setKeepHorizontalScrollingSpace(true); /* ** Statistics ** */ - - int imagesCount = MapManager.getMapList(getPlayer().getUniqueId()).size(); - int mapPartCount = MapManager.getMapPartCount(getPlayer().getUniqueId()); + int imagesCount = MapManager.getMapList(p.getUniqueId()).size(); + int mapPartCount = MapManager.getMapPartCount(p.getUniqueId()); int mapGlobalLimit = PluginConfiguration.MAP_GLOBAL_LIMIT.get(); int mapPersonalLimit = PluginConfiguration.MAP_PLAYER_LIMIT.get(); diff --git a/src/main/resources/help/maptool.txt b/src/main/resources/help/maptool.txt index 5110868..9b83e58 100644 --- a/src/main/resources/help/maptool.txt +++ b/src/main/resources/help/maptool.txt @@ -9,5 +9,6 @@ getremaining: Gives you the remaining maps that could not fit in your inventory 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. migrate: Lauches the migration process from V2.7 to V3.x. help : Use help for more information about a command. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f92a42c..490e06d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -20,11 +20,15 @@ permissions: imageonmap.userender: true imageonmap.new: true imageonmap.list: true + imageonmap.listother: true imageonmap.get: true + imageonmap.getother: true imageonmap.explore: true + imageonmap.exploreother: true imageonmap.rename: true imageonmap.removesplattermap: true imageonmap.delete: true + imageonmap.deleteother: false imageonmap.bypasssize: false imageonmap.userender: @@ -36,16 +40,28 @@ permissions: default: true imageonmap.list: - description: "Allows you to list the images you rendered." - default: true + description: "Allows you to list the images you rendered." + default: true + + imageonmap.listother: + description: "Allows you to list the images a player have rendered." + default: false imageonmap.get: - description: "Allows you to get a new map among the ones you already rendered, and related commands (/maptool getremaining)." - default: true + description: "Allows you to get a new map among the ones you already rendered, and related commands (/maptool getremaining)." + default: true + + imageonmap.getother: + description: "Allows you to get a new map among the ones a player have already rendered." + default: false imageonmap.explore: - description: "Allows you to open a GUI with all your maps." - default: true + description: "Allows you to open a GUI with all your maps." + default: true + + imageonmap.exploreother: + description: "Allows you to open a GUI with all of the player maps." + default: false imageonmap.rename: description: "Allows you to rename a map you rendered in the past." @@ -55,6 +71,10 @@ permissions: description: "Allows you to delete a map you rendered in the past." default: true + imageonmap.deleteother: + description: "Allows you to delete a map a player rendered in the past." + default: false + imageonmap.removesplattermap: description: "Allows you to remove a splatter map from a wall by sneaking and breaking a map." default: true