The permissions update.

* NEW: added permissions for everything.
This commit is contained in:
Amaury Carrade 2018-01-24 00:16:58 +01:00
parent a278a42b01
commit f92d90683d
No known key found for this signature in database
GPG Key ID: 73235214BDBB8752
14 changed files with 304 additions and 55 deletions

View File

@ -1,7 +1,7 @@
ImageOnMap ImageOnMap
========== ==========
Repo for ImageOnMap, a bukkit plugin Repo for ImageOnMap, a bukkit plugin.
## Features ## Features
@ -14,7 +14,7 @@ ImageOnMap allows you to load a picture from the Internet to a Minecraft map.
- Your image will be centered. - Your image will be centered.
- You can put your map in an item frame. - You can put your map in an item frame.
This plugin is a free software lisensed under the GNU General Public License (version 3 or above). The source code is published on GitHub. You can also get unstable development builds here. This plugin is a free software licenced under the GNU General Public License (version 3 or above). You can also get unstable development builds here.
## Quick guide ## Quick guide
@ -34,7 +34,7 @@ Renders an image and gives a map to the player with it.
- The link must be complete, do not forget that the chat limit is 240 characters. - The link must be complete, do not forget that the chat limit is 240 characters.
- You can use an URL shortener like tinyURL or bitly. - You can use an URL shortener like tinyURL or bitly.
- If you want a picture in one map, type resize after the link. - If you want a picture in one map, type resize after the link.
- Permission: `imageonmap.userender` - Permission: `imageonmap.new` (or `imageonmap.userender`—legacy, but will be kept in the plugin).
### `/maps` ### `/maps`
@ -46,6 +46,7 @@ Opens a GUI to see, retrieve and manage the user's maps.
- A book is displayed too to see some usage statistics (maps created, quotas). - A book is displayed too to see some usage statistics (maps created, quotas).
- An user can retrieve a map by left-clicking it, or manage it by right-clicking. - An user can retrieve a map by left-clicking it, or manage it by right-clicking.
- Maps can be renamed (for organization), deleted (but they won't render in game anymore!), or partially retrieved (for posters maps containing more than one map). - Maps can be renamed (for organization), deleted (but they won't render in game anymore!), or partially retrieved (for posters maps containing more than one map).
- Permission: `imageonmap.list`, plus `imageonmap.get`, `imageonmap.rename` and `imageonmap.delete` for actions into the GUI.
### `/maptool <new|list|get|delete|explore|migrate>` ### `/maptool <new|list|get|delete|explore|migrate>`
@ -56,7 +57,19 @@ Main command to manage the maps. The less used in everyday usage, too.
- `/maptool new` is an alias of `/tomap`. - `/maptool new` is an alias of `/tomap`.
- `/maptool explore` is an alias of `/maps`. - `/maptool explore` is an alias of `/maps`.
- `/maptool migrate` migrates the old maps when you upgrade from IoM <= 2.7 to IoM 3.0. You HAVE TO execute this command to retrieve all maps when you do such a migration. - `/maptool migrate` migrates the old maps when you upgrade from IoM <= 2.7 to IoM 3.0. You HAVE TO execute this command to retrieve all maps when you do such a migration.
- Permissions:
- `imageonmap.new` for `/maptool new`;
- `imageonmap.list` for both `/maptool list` and `/maptool explore`;
- `imageonmap.get` for `/maptool get`;
- `imageonmap.delete` for `/maptool delete`;
- `imageonmap.administrative` for `/maptool migrate`.
### About the permissions
All permissions are by default granted to everyone, with the exception of `imageonmap.administrative`. We believe that in most cases, servers administrators want to give the availability to create images on maps to every player.
Negate a permission using a plugin manager to remove it, if you want to restrict this possibility to a set of users.
You can grant `imageonmap.*` to users, as this permission is a shortcut for all _user_ permissions (excluding `imageonmap.administrative`).
## Configuration ## Configuration
@ -77,7 +90,9 @@ map-global-limit: 0
map-player-limit: 0 map-player-limit: 0
``` ```
## New features in the 3.0 version ## Changelog
### 3.0
The 3.0 release is a complete rewrite of the original ImageOnMap plugin, now based on zLib, which adds many feature and fixes many bugs. The 3.0 release is a complete rewrite of the original ImageOnMap plugin, now based on zLib, which adds many feature and fixes many bugs.
@ -94,8 +109,12 @@ You will find amongst the new features:
- Asynchronous maps rendering (your server won't freeze anymore when rendering big maps, and you can queue multiple map renderings !) - Asynchronous maps rendering (your server won't freeze anymore when rendering big maps, and you can queue multiple map renderings !)
- UUID management (which requires to run `/maptool migrate`) - UUID management (which requires to run `/maptool migrate`)
### 3.1
- Fixed permissions support by adding a full set of permissions for every action of the plugin.
## Data collection ## Data collection
We use metrics to collect basic informations about the usage of this plugin. This can be disabled by setting "collect-data" to false in config.yml. We use metrics to collect basic information about the usage of this plugin. This can be disabled by setting `collect-data` to false in `config.yml`.

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>fr.moribus</groupId> <groupId>fr.moribus</groupId>
<artifactId>ImageOnMap</artifactId> <artifactId>ImageOnMap</artifactId>
<version>3.0</version> <version>3.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>

View File

@ -0,0 +1,75 @@
/*
* Copyright or © or Copr. AmauryCarrade (2015)
*
* http://amaury.carrade.eu
*
* 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;
import org.bukkit.permissions.Permissible;
public enum Permissions
{
NEW("imageonmap.new", "imageonmap.userender"),
LIST("imageonmap.list"),
GET("imageonmap.get"),
RENAME("imageonmap.rename"),
DELETE("imageonmap.delete"),
ADMINISTRATIVE("imageonmap.administrative")
;
private final String permission;
private final String[] aliases;
Permissions(String permission, String... aliases)
{
this.permission = permission;
this.aliases = aliases;
}
/**
* Checks if this permission is granted to the given permissible.
*
* @param permissible The permissible to check.
* @return {@code true} if this permission is granted to the permissible.
*/
public boolean grantedTo(Permissible permissible)
{
if (permissible.hasPermission(permission))
return true;
for (String alias : aliases)
if (permissible.hasPermission(alias))
return true;
return false;
}
}

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.commands.maptool; package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager; import fr.moribus.imageonmap.map.MapManager;
@ -29,6 +30,7 @@ import fr.zcraft.zlib.components.i18n.I;
import fr.zcraft.zlib.components.rawtext.RawText; import fr.zcraft.zlib.components.rawtext.RawText;
import fr.zcraft.zlib.tools.PluginLogger; import fr.zcraft.zlib.tools.PluginLogger;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
@ -83,4 +85,10 @@ public class DeleteCommand extends IoMCommand
return null; return null;
} }
@Override
public boolean canExecute(CommandSender sender)
{
return Permissions.DELETE.grantedTo(sender);
}
} }

View File

@ -19,11 +19,13 @@
package fr.moribus.imageonmap.commands.maptool; package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.gui.MapListGui; import fr.moribus.imageonmap.gui.MapListGui;
import fr.zcraft.zlib.components.commands.CommandException; import fr.zcraft.zlib.components.commands.CommandException;
import fr.zcraft.zlib.components.commands.CommandInfo; import fr.zcraft.zlib.components.commands.CommandInfo;
import fr.zcraft.zlib.components.gui.Gui; import fr.zcraft.zlib.components.gui.Gui;
import org.bukkit.command.CommandSender;
@CommandInfo (name = "explore") @CommandInfo (name = "explore")
@ -34,4 +36,10 @@ public class ExploreCommand extends IoMCommand
{ {
Gui.open(playerSender(), new MapListGui()); Gui.open(playerSender(), new MapListGui());
} }
@Override
public boolean canExecute(CommandSender sender)
{
return Permissions.LIST.grantedTo(sender);
}
} }

View File

@ -18,10 +18,12 @@
package fr.moribus.imageonmap.commands.maptool; package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.zcraft.zlib.components.commands.CommandException; import fr.zcraft.zlib.components.commands.CommandException;
import fr.zcraft.zlib.components.commands.CommandInfo; import fr.zcraft.zlib.components.commands.CommandInfo;
import fr.zcraft.zlib.components.i18n.I; import fr.zcraft.zlib.components.i18n.I;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
@ -47,4 +49,10 @@ public class GetCommand extends IoMCommand
return getMatchingMapNames(playerSender(), args[0]); return getMatchingMapNames(playerSender(), args[0]);
return null; return null;
} }
@Override
public boolean canExecute(CommandSender sender)
{
return Permissions.GET.grantedTo(sender);
}
} }

View File

@ -18,11 +18,13 @@
package fr.moribus.imageonmap.commands.maptool; package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.ui.MapItemManager; import fr.moribus.imageonmap.ui.MapItemManager;
import fr.zcraft.zlib.components.commands.CommandException; import fr.zcraft.zlib.components.commands.CommandException;
import fr.zcraft.zlib.components.commands.CommandInfo; import fr.zcraft.zlib.components.commands.CommandInfo;
import fr.zcraft.zlib.components.i18n.I; import fr.zcraft.zlib.components.i18n.I;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandInfo (name = "getremaining", aliases = {"getrest"}) @CommandInfo (name = "getremaining", aliases = {"getrest"})
@ -50,4 +52,10 @@ public class GetRemainingCommand extends IoMCommand
info(I.tn("There is {0} map remaining.", "There are {0} maps remaining.", MapItemManager.getCacheSize(player))); info(I.tn("There is {0} map remaining.", "There are {0} maps remaining.", MapItemManager.getCacheSize(player)));
} }
} }
@Override
public boolean canExecute(CommandSender sender)
{
return Permissions.NEW.grantedTo(sender) || Permissions.GET.grantedTo(sender);
}
} }

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.commands.maptool; package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager; import fr.moribus.imageonmap.map.MapManager;
@ -31,6 +32,7 @@ import fr.zcraft.zlib.tools.items.ItemStackBuilder;
import fr.zcraft.zlib.tools.text.RawMessage; import fr.zcraft.zlib.tools.text.RawMessage;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List; import java.util.List;
@ -81,4 +83,10 @@ public class ListCommand extends IoMCommand
.item() .item()
); );
} }
@Override
public boolean canExecute(CommandSender sender)
{
return Permissions.LIST.grantedTo(sender);
}
} }

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.commands.maptool; package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.migration.MigratorExecutor; import fr.moribus.imageonmap.migration.MigratorExecutor;
import fr.zcraft.zlib.components.commands.CommandException; import fr.zcraft.zlib.components.commands.CommandException;
@ -45,6 +46,6 @@ public class MigrateCommand extends IoMCommand
@Override @Override
public boolean canExecute(CommandSender sender) public boolean canExecute(CommandSender sender)
{ {
return sender.isOp(); return sender.isOp() || Permissions.ADMINISTRATIVE.grantedTo(sender);
} }
} }

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.commands.maptool; package fr.moribus.imageonmap.commands.maptool;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.commands.IoMCommand;
import fr.moribus.imageonmap.image.ImageRendererExecutor; import fr.moribus.imageonmap.image.ImageRendererExecutor;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
@ -26,6 +27,7 @@ import fr.zcraft.zlib.components.commands.CommandInfo;
import fr.zcraft.zlib.components.i18n.I; import fr.zcraft.zlib.components.i18n.I;
import fr.zcraft.zlib.components.worker.WorkerCallback; import fr.zcraft.zlib.components.worker.WorkerCallback;
import fr.zcraft.zlib.tools.PluginLogger; import fr.zcraft.zlib.tools.PluginLogger;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.net.MalformedURLException; import java.net.MalformedURLException;
@ -84,4 +86,10 @@ public class NewCommand extends IoMCommand
} }
}); });
} }
@Override
public boolean canExecute(CommandSender sender)
{
return Permissions.NEW.grantedTo(sender);
}
} }

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.gui; package fr.moribus.imageonmap.gui;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager; import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.MapManagerException; import fr.moribus.imageonmap.map.MapManagerException;
@ -170,6 +171,14 @@ public class ConfirmDeleteMapGui extends ActionGui
@GuiAction ("delete") @GuiAction ("delete")
protected void delete() protected void delete()
{ {
// Does the player still have the permission to delete a map?
if (!Permissions.DELETE.grantedTo(getPlayer()))
{
I.sendT(getPlayer(), "{ce}You are no longer allowed to do that.");
close();
return;
}
MapManager.clear(getPlayer().getInventory(), mapToDelete); MapManager.clear(getPlayer().getInventory(), mapToDelete);
try try

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.gui; package fr.moribus.imageonmap.gui;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.PosterMap; import fr.moribus.imageonmap.map.PosterMap;
import fr.moribus.imageonmap.map.SingleMap; import fr.moribus.imageonmap.map.SingleMap;
@ -46,38 +47,41 @@ public class MapDetailGui extends ExplorerGui<Short>
@Override @Override
protected ItemStack getViewItem(int x, int y) protected ItemStack getViewItem(int x, int y)
{ {
Material partMaterial = Material.PAPER; final Material partMaterial = y % 2 == x % 2 ? Material.EMPTY_MAP : Material.PAPER;
if((y % 2 == 0 && x % 2 == 0) || (y % 2 == 1 && x % 2 == 1))
partMaterial = Material.EMPTY_MAP;
return new ItemStackBuilder(partMaterial) final ItemStackBuilder builder = new ItemStackBuilder(partMaterial)
.title(I.t(getPlayerLocale(), "{green}Map part")) .title(I.t(getPlayerLocale(), "{green}Map part"))
.lore(I.t(getPlayerLocale(), "{gray}Row: {white}{0}", y + 1)) .lore(I.t(getPlayerLocale(), "{gray}Row: {white}{0}", y + 1))
.lore(I.t(getPlayerLocale(), "{gray}Column: {white}{0}", x + 1)) .lore(I.t(getPlayerLocale(), "{gray}Column: {white}{0}", x + 1));
.loreLine()
.lore(I.t(getPlayerLocale(), "{gray}» {white}Click{gray} to get only this part")) if (Permissions.GET.grantedTo(getPlayer()))
.item(); builder.loreLine().lore(I.t(getPlayerLocale(), "{gray}» {white}Click{gray} to get only this part"));
return builder.item();
} }
@Override @Override
protected ItemStack getViewItem(Short mapId) protected ItemStack getViewItem(Short mapId)
{ {
int index = ((PosterMap) map).getIndex(mapId); final int index = ((PosterMap) map).getIndex(mapId);
Material partMaterial = Material.PAPER; final Material partMaterial = index % 2 == 0 ? Material.EMPTY_MAP : Material.PAPER;
if(index % 2 == 0)
partMaterial = Material.EMPTY_MAP;
return new ItemStackBuilder(partMaterial) final ItemStackBuilder builder = new ItemStackBuilder(partMaterial)
.title(I.t(getPlayerLocale(), "{green}Map part")) .title(I.t(getPlayerLocale(), "{green}Map part"))
.lore(I.t(getPlayerLocale(), "{gray}Part: {white}{0}", index + 1)) .lore(I.t(getPlayerLocale(), "{gray}Part: {white}{0}", index + 1));
.loreLine()
.lore(I.t(getPlayerLocale(), "{gray}» {white}Click{gray} to get only this part")) if (Permissions.GET.grantedTo(getPlayer()))
.item(); builder.loreLine().lore(I.t(getPlayerLocale(), "{gray}» {white}Click{gray} to get only this part"));
return builder.item();
} }
@Override @Override
protected ItemStack getPickedUpItem(int x, int y) protected ItemStack getPickedUpItem(int x, int y)
{ {
if (!Permissions.GET.grantedTo(getPlayer()))
return null;
if (map instanceof SingleMap) if (map instanceof SingleMap)
{ {
return MapItemManager.createMapItem((SingleMap)map); return MapItemManager.createMapItem((SingleMap)map);
@ -93,7 +97,10 @@ public class MapDetailGui extends ExplorerGui<Short>
@Override @Override
protected ItemStack getPickedUpItem(Short mapId) protected ItemStack getPickedUpItem(Short mapId)
{ {
PosterMap poster = (PosterMap) map; if (!Permissions.GET.grantedTo(getPlayer()))
return null;
final PosterMap poster = (PosterMap) map;
return MapItemManager.createMapItem(poster, poster.getIndex(mapId)); return MapItemManager.createMapItem(poster, poster.getIndex(mapId));
} }
@ -131,25 +138,41 @@ public class MapDetailGui extends ExplorerGui<Short>
setDataShape(1,1); setDataShape(1,1);
} }
final boolean canRename = Permissions.RENAME.grantedTo(getPlayer());
final boolean canDelete = Permissions.DELETE.grantedTo(getPlayer());
action("rename", getSize() - 7, new ItemStackBuilder(Material.BOOK_AND_QUILL) int renameSlot = getSize() - 7;
int deleteSlot = getSize() - 6;
if (!canRename)
deleteSlot--;
if (canRename)
{
action("rename", renameSlot, new ItemStackBuilder(Material.BOOK_AND_QUILL)
.title(I.t(getPlayerLocale(), "{blue}Rename this image")) .title(I.t(getPlayerLocale(), "{blue}Rename this image"))
.longLore(I.t(getPlayerLocale(), "{gray}Click here to rename this image; this is used for your own organization.")) .longLore(I.t(getPlayerLocale(), "{gray}Click here to rename this image; this is used for your own organization."))
); );
}
action("delete", getSize() - 6, new ItemStackBuilder(Material.BARRIER) if (canDelete)
{
action("delete", deleteSlot, new ItemStackBuilder(Material.BARRIER)
.title(I.t(getPlayerLocale(), "{red}Delete this image")) .title(I.t(getPlayerLocale(), "{red}Delete this image"))
.longLore(I.t(getPlayerLocale(), "{gray}Deletes this map {white}forever{gray}. This action cannot be undone!")) .longLore(I.t(getPlayerLocale(), "{gray}Deletes this map {white}forever{gray}. This action cannot be undone!"))
.loreLine() .loreLine()
.longLore(I.t(getPlayerLocale(), "{gray}You will be asked to confirm your choice if you click here.")) .longLore(I.t(getPlayerLocale(), "{gray}You will be asked to confirm your choice if you click here."))
); );
}
// To keep the controls centered, the back button is shifted to the right when the // To keep the controls centered, the back button is shifted to the right when the
// arrow isn't displayed, so when the map fit on the grid without sliders. // arrow isn't displayed, so when the map fit on the grid without sliders.
int backSlot = getSize() - 4; int backSlot = getSize() - 4;
if(map instanceof PosterMap && ((PosterMap) map).getColumnCount() <= INVENTORY_ROW_SIZE) if (!canRename && !canDelete)
backSlot = getSize() - 5;
else if (map instanceof PosterMap && ((PosterMap) map).getColumnCount() <= INVENTORY_ROW_SIZE)
backSlot++; backSlot++;
action("back", backSlot, new ItemStackBuilder(Material.EMERALD) action("back", backSlot, new ItemStackBuilder(Material.EMERALD)
@ -162,11 +185,24 @@ public class MapDetailGui extends ExplorerGui<Short>
@GuiAction ("rename") @GuiAction ("rename")
public void rename() public void rename()
{ {
if (!Permissions.RENAME.grantedTo(getPlayer()))
{
I.sendT(getPlayer(), "{ce}You are no longer allowed to do that.");
update();
return;
}
PromptGui.prompt(getPlayer(), new Callback<String>() PromptGui.prompt(getPlayer(), new Callback<String>()
{ {
@Override @Override
public void call(String newName) public void call(String newName)
{ {
if (!Permissions.RENAME.grantedTo(getPlayer()))
{
I.sendT(getPlayer(), "{ce}You are no longer allowed to do that.");
return;
}
if (newName == null || newName.isEmpty()) if (newName == null || newName.isEmpty())
{ {
I.sendT(getPlayer(), "{ce}Map names can't be empty."); I.sendT(getPlayer(), "{ce}Map names can't be empty.");
@ -182,6 +218,13 @@ public class MapDetailGui extends ExplorerGui<Short>
@GuiAction ("delete") @GuiAction ("delete")
public void delete() public void 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); Gui.open(getPlayer(), new ConfirmDeleteMapGui(map), this);
} }

View File

@ -17,6 +17,7 @@
*/ */
package fr.moribus.imageonmap.gui; package fr.moribus.imageonmap.gui;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.PluginConfiguration; import fr.moribus.imageonmap.PluginConfiguration;
import fr.moribus.imageonmap.map.ImageMap; import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager; import fr.moribus.imageonmap.map.MapManager;
@ -57,7 +58,7 @@ public class MapListGui extends ExplorerGui<ImageMap>
mapDescription = I.t(getPlayerLocale(), "{white}Poster map ({0} parts)", poster.getMapCount()); mapDescription = I.t(getPlayerLocale(), "{white}Poster map ({0} parts)", poster.getMapCount());
} }
} }
return new ItemStackBuilder(Material.MAP) ItemStackBuilder builder = new ItemStackBuilder(Material.MAP)
/// Displayed title of a map on the list GUI /// Displayed title of a map on the list GUI
.title(I.t(getPlayerLocale(), "{green}{bold}{0}", map.getName())) .title(I.t(getPlayerLocale(), "{green}{bold}{0}", map.getName()))
@ -65,20 +66,28 @@ public class MapListGui extends ExplorerGui<ImageMap>
.loreLine() .loreLine()
/// Map ID displayed in the tooltip of a map on the list GUI /// Map ID displayed in the tooltip of a map on the list GUI
.lore(I.t(getPlayerLocale(), "{gray}Map ID: {0}", map.getId())) .lore(I.t(getPlayerLocale(), "{gray}Map ID: {0}", map.getId()))
.loreLine() .loreLine();
.lore(I.t(getPlayerLocale(), "{gray}» {white}Left-click{gray} to get this map"))
.lore(I.t(getPlayerLocale(), "{gray}» {white}Right-click{gray} for details and options"))
.item(); if (Permissions.GET.grantedTo(getPlayer()))
builder.lore(I.t(getPlayerLocale(), "{gray}» {white}Left-click{gray} to get this map"));
builder.lore(I.t(getPlayerLocale(), "{gray}» {white}Right-click{gray} for details and options"));
return builder.item();
} }
@Override @Override
protected ItemStack getEmptyViewItem() protected ItemStack getEmptyViewItem()
{ {
return new ItemStackBuilder(Material.BARRIER) ItemStackBuilder builder = new ItemStackBuilder(Material.BARRIER)
.title(I.t(getPlayerLocale(), "{red}You don't have any map.")) .title(I.t(getPlayerLocale(), "{red}You don't have any map."));
.longLore(I.t(getPlayerLocale(), "{gray}Get started by creating a new one using {white}/tomap <URL> [resize]{gray}!"))
.item(); if (Permissions.NEW.grantedTo(getPlayer()))
builder.longLore(I.t(getPlayerLocale(), "{gray}Get started by creating a new one using {white}/tomap <URL> [resize]{gray}!"));
else
builder.longLore(I.t(getPlayerLocale(), "{gray}Unfortunately, you are not allowed to create one."));
return builder.item();
} }
@Override @Override
@ -90,6 +99,9 @@ public class MapListGui extends ExplorerGui<ImageMap>
@Override @Override
protected ItemStack getPickedUpItem(ImageMap map) protected ItemStack getPickedUpItem(ImageMap map)
{ {
if (!Permissions.GET.grantedTo(getPlayer()))
return null;
if (map instanceof SingleMap) if (map instanceof SingleMap)
{ {
return MapItemManager.createMapItem(map.getMapsIDs()[0], map.getName()); return MapItemManager.createMapItem(map.getMapsIDs()[0], map.getName());
@ -114,6 +126,7 @@ public class MapListGui extends ExplorerGui<ImageMap>
{ {
ImageMap[] maps = MapManager.getMaps(getPlayer().getUniqueId()); ImageMap[] maps = MapManager.getMaps(getPlayer().getUniqueId());
setData(maps); setData(maps);
/// The maps list GUI title /// The maps list GUI title
setTitle(I.t(getPlayerLocale(), "{black}Your maps {reset}({0})", maps.length)); setTitle(I.t(getPlayerLocale(), "{black}Your maps {reset}({0})", maps.length));

View File

@ -1,6 +1,6 @@
name: ImageOnMap name: ImageOnMap
main: fr.moribus.imageonmap.ImageOnMap main: fr.moribus.imageonmap.ImageOnMap
version: 3.0 version: 3.1
commands: commands:
tomap: tomap:
@ -12,6 +12,47 @@ commands:
description: manage maps through a GUI description: manage maps through a GUI
permissions: permissions:
imageonmap.*:
description: "Grants all the user permissions (excluding administrative ones)."
default: true
children:
imageonmap.userender: true
imageonmap.new: true
imageonmap.list: true
imageonmap.get: true
imageonmap.explore: true
imageonmap.rename: true
imageonmap.delete: true
imageonmap.administrative: false
imageonmap.userender: imageonmap.userender:
description: Allows you to use /tomap description: "Allows you to use /tomap and related commands (/maptool getremaing). Alias of imageonmap.new."
default: true
imageonmap.new:
description: "Allows you to use /tomap and related commands (/maptool getremaing)."
default: true
imageonmap.list:
description: "Allows you to list the images you rendered."
default: true
imageonmap.get:
description: "Allows you to get a new map among the ones you already rendered, and related commands (/maptool getremaing)."
default: true
imageonmap.explore:
description: "Allows you to open a GUI with all your maps."
default: true
imageonmap.rename:
description: "Allows you to rename a map you rendered in the past."
default: true
imageonmap.delete:
description: "Allows you to delete a map you rendered in the past."
default: true
imageonmap.administrative:
description: "Allows you to perform administrative tasks (like /maptool migrate)."
default: op default: op