Merge pull request #48 from kirbykirby56/Imbadatgit

Add Administrative commands
This commit is contained in:
Vlammar 2020-08-26 00:13:02 +02:00 committed by GitHub
commit 9b2a48aea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 326 additions and 7 deletions

View File

@ -36,6 +36,7 @@
package fr.moribus.imageonmap;
import fr.moribus.imageonmap.commands.maptool.*;
import fr.moribus.imageonmap.image.ImageIOExecutor;
import fr.moribus.imageonmap.image.ImageRendererExecutor;
@ -55,12 +56,12 @@ import org.bstats.bukkit.Metrics;
import java.io.File;
import java.io.IOException;
public final class ImageOnMap extends ZPlugin
{
static private final String IMAGES_DIRECTORY_NAME = "images";
static private final String MAPS_DIRECTORY_NAME = "maps";
static private ImageOnMap plugin;
private File imagesDirectory;
private final File mapsDirectory;
@ -83,6 +84,7 @@ public final class ImageOnMap extends ZPlugin
return new File(imagesDirectory, "map"+mapID+".png");
}
@SuppressWarnings ("unchecked")
@Override
public void onEnable()
@ -99,11 +101,12 @@ public final class ImageOnMap extends ZPlugin
this.setEnabled(false);
return;
}
saveDefaultConfig();
loadComponents(I18n.class, Gui.class, Commands.class, PluginConfiguration.class, ImageIOExecutor.class, ImageRendererExecutor.class);
//Init all the things !
I18n.setPrimaryLocale(PluginConfiguration.LANG.get());
@ -116,6 +119,9 @@ public final class ImageOnMap extends ZPlugin
NewCommand.class,
ListCommand.class,
GetCommand.class,
GetOtherCommand.class,
ListOtherCommand.class,
DeleteOtherCommand.class,
DeleteCommand.class,
GetRemainingCommand.class,
ExploreCommand.class,

View File

@ -1,4 +1,5 @@
/*
* 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)
@ -42,16 +43,19 @@ public enum Permissions
{
NEW("imageonmap.new", "imageonmap.userender"),
LIST("imageonmap.list"),
LISTOTHER("imageonmap.listother"),
GET("imageonmap.get"),
GETOTHER("imageonmap.getother"),
RENAME("imageonmap.rename"),
REMOVE_SPLATTER_MAP("imageonmap.removesplattermap"),
DELETE("imageonmap.delete"),
DELETEOTHER("imageonmap.deleteother"),
ADMINISTRATIVE("imageonmap.administrative"),
BYPASS_SIZE("imageonmap.bypasssize")
;
private final String permission;
private final String[] aliases;
@ -78,4 +82,4 @@ public enum Permissions
return false;
}
}
}

View File

@ -0,0 +1,97 @@
/*
* Copyright (C) 2013 Moribus
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
*
* 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 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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.zlib.components.commands.CommandException;
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.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.UUID;
@CommandInfo (name = "deleteother", usageParameters = "<player name> <map name>")
@WithFlags ({"confirm"})
public class DeleteOtherCommand extends IoMCommand
{
@Override
protected void run() throws CommandException
{
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 <playername> <mapname>"));
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();
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) MapManager.clear(player.getInventory(), map);
try
{
MapManager.deleteMap(map);
getPlayer().sendMessage(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.")));
}
}
@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

@ -0,0 +1,80 @@
/*
* Copyright (C) 2013 Moribus
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
*
* 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 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
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;
@CommandInfo (name = "getother", usageParameters = "<PlayerName> <MapName>")
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 <playername> <mapname>"));
//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)"));
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();
}
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);
map.give(playerSender());
return;
}
@Override
public boolean canExecute(CommandSender sender)
{
return Permissions.GETOTHER.grantedTo(sender);
}
}

View File

@ -0,0 +1,122 @@
/*
* Copyright (C) 2013 Moribus
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
*
* 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 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap;
import fr.zcraft.zlib.components.commands.CommandException;
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;
@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>"));
if(!playerSender().hasPermission("imageonmap.list.other")) {
warning(I.t("You do not have permission for this command. (imageonmap.list.other)"));
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){
}
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

@ -2,9 +2,12 @@ This command manages and creates ImagesOnMaps.
new: Creates a new ImageOnMap
delete: Deletes a map.
delete-noconfirm: Deletes a map. Deletion is permanent and made without confirmation
deleteother: Deletes another map.
get: Gives you a map.
getother: Gets another player's map.
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.
migrate: Lauches the migration process from V2.7 to V3.x.
help : Use help for more information about a command.
help : Use help for more information about a command.

View File

@ -0,0 +1,4 @@
Gets another player's map.
§6<playername>: §rThe name of the player who owns the map.
§6<mapname>: §rThe name of the map. Use /maptool listother to get map names.

View File

@ -0,0 +1,3 @@
Lists another player's maps.
§6<playername>: §rThe name of the player you want to list map from.