Add administrative commands

This commit is contained in:
kirbykirby56 2018-03-24 20:46:32 -04:00
parent 3d7d2fd27e
commit 4885198888
13 changed files with 390 additions and 11 deletions

View File

@ -18,13 +18,17 @@
package fr.moribus.imageonmap;
import fr.moribus.imageonmap.commands.maptool.DebugCommand;
import fr.moribus.imageonmap.commands.maptool.DeleteCommand;
import fr.moribus.imageonmap.commands.maptool.ExploreCommand;
import fr.moribus.imageonmap.commands.maptool.GetCommand;
import fr.moribus.imageonmap.commands.maptool.GetRemainingCommand;
import fr.moribus.imageonmap.commands.maptool.DeleteOtherCommand;
import fr.moribus.imageonmap.commands.maptool.ListCommand;
import fr.moribus.imageonmap.commands.maptool.ListOtherCommand;
import fr.moribus.imageonmap.commands.maptool.MigrateCommand;
import fr.moribus.imageonmap.commands.maptool.NewCommand;
import fr.moribus.imageonmap.commands.maptool.GetCommand;
import fr.moribus.imageonmap.commands.maptool.GetRemainingCommand;
import fr.moribus.imageonmap.commands.maptool.GetOtherCommand;
import fr.moribus.imageonmap.commands.maptool.ExploreCommand;
import fr.moribus.imageonmap.image.ImageIOExecutor;
import fr.moribus.imageonmap.image.ImageRendererExecutor;
import fr.moribus.imageonmap.image.MapInitEvent;
@ -41,12 +45,12 @@ import fr.zcraft.zlib.tools.PluginLogger;
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;
@ -69,6 +73,7 @@ public final class ImageOnMap extends ZPlugin
return new File(imagesDirectory, "map"+mapID+".png");
}
@SuppressWarnings ("unchecked")
@Override
public void onEnable()
@ -85,11 +90,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 !
MetricsLite.startMetrics();
I18n.setPrimaryLocale(PluginConfiguration.LANG.get());
@ -101,8 +107,12 @@ public final class ImageOnMap extends ZPlugin
Commands.register(
"maptool",
NewCommand.class,
DebugCommand.class,
ListCommand.class,
GetCommand.class,
GetOtherCommand.class,
ListOtherCommand.class,
DeleteOtherCommand.class,
DeleteCommand.class,
GetRemainingCommand.class,
ExploreCommand.class,

View File

@ -1,5 +1,5 @@
/*
* Copyright or © or Copr. AmauryCarrade (2015)
* Copyright or © or Copr. AmauryCarrade (2015)
*
* http://amaury.carrade.eu
*
@ -38,9 +38,12 @@ public enum Permissions
{
NEW("imageonmap.new", "imageonmap.userender"),
LIST("imageonmap.list"),
LISTOTHER("imageonmap.listother"),
GET("imageonmap.get"),
GETOTHER("imageonmap.getother"),
RENAME("imageonmap.rename"),
DELETE("imageonmap.delete"),
DELETEOTHER("imageonmap.deleteother"),
ADMINISTRATIVE("imageonmap.administrative")
;
@ -72,4 +75,4 @@ public enum Permissions
return false;
}
}
}

View File

@ -0,0 +1,41 @@
/*
* 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.PluginConfiguration;
import fr.moribus.imageonmap.commands.IoMCommand;
import fr.zcraft.zlib.components.commands.CommandException;
import fr.zcraft.zlib.components.commands.CommandInfo;
import org.bukkit.entity.Player;
@CommandInfo (name = "debug")
public class DebugCommand extends IoMCommand
{
@Override
protected void run() throws CommandException
{
Player p = playerSender();
p.sendMessage("Limit Map Size X" + PluginConfiguration.LIMIT_SIZE_X.get().toString());
p.sendMessage("Limit Map Size Y" + PluginConfiguration.LIMIT_SIZE_Y.get().toString());
p.sendMessage("Global Map Limit" + PluginConfiguration.MAP_GLOBAL_LIMIT.get().toString());
p.sendMessage("Player Map Limit" + PluginConfiguration.MAP_PLAYER_LIMIT.get().toString());
p.sendMessage("Collect Data" + PluginConfiguration.COLLECT_DATA.get().toString());
p.sendMessage("Save Full Image" + PluginConfiguration.SAVE_FULL_IMAGE.get().toString());
}
}

View File

@ -0,0 +1,98 @@
/*
* 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(args.length < 2) warning(I.t("Not enough parameters! Usage: /maptool deleteother <playername> <mapname>"));
if(!playerSender().hasPermission("imageonmap.delete.other")) {
warning(I.t("You do not have permission for this command. (imageonmap.delete.other)"));
return;
}
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);
//if(player == null) MapManager.clear(op.getPlayer().getInventory(), map);
try
{
MapManager.deleteMap(map);
info(I.t("Map successfully deleted."));
}
catch (MapManagerException ex)
{
PluginLogger.warning("A non-existent map was requested to be deleted", ex);
warning(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,124 @@
/*
* 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 ItemStackBuilder(Material.MAP)
.title(ChatColor.GREEN + "" + ChatColor.BOLD + map.getName())
.lore(ChatColor.GRAY + map.getId() + ", " + size)
.lore("")
.lore(I.t("{white}Click{gray} to get this map"))
.hideAttributes()
.item()
);
}
@Override
public boolean canExecute(CommandSender sender)
{
return Permissions.LISTOTHER.grantedTo(sender);
}
}

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.map;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.ui.MapItemManager;
import fr.zcraft.zlib.components.i18n.I;
import org.bukkit.Material;
@ -26,6 +27,7 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ -47,7 +49,6 @@ public abstract class ImageMap implements ConfigurationSerializable
private final UUID userUUID;
private final Type mapType;
private String name;
protected ImageMap(UUID userUUID, Type mapType)
{
this(userUUID, mapType, null, null);
@ -84,6 +85,11 @@ public abstract class ImageMap implements ConfigurationSerializable
return MapItemManager.give(player, this);
}
public static File getFullImageFile(short mapIDstart, short mapIDend)
{
return new File(ImageOnMap.getPlugin().getImagesDirectory(), "_"+mapIDstart+"-"+mapIDend+".png");
}
/* ====== Serialization methods ====== */
static public ImageMap fromConfig(Map<String, Object> map, UUID userUUID) throws InvalidConfigurationException

View File

@ -18,12 +18,13 @@
package fr.moribus.imageonmap.map;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.PluginConfiguration;
import fr.moribus.imageonmap.image.ImageIOExecutor;
import fr.moribus.imageonmap.image.PosterImage;
import fr.moribus.imageonmap.map.MapManagerException.Reason;
import fr.zcraft.zlib.tools.PluginLogger;
import fr.moribus.imageonmap.ImageOnMap;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;

View File

@ -18,10 +18,11 @@
package fr.moribus.imageonmap.map;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.PluginConfiguration;
import fr.moribus.imageonmap.map.MapManagerException.Reason;
import fr.zcraft.zlib.tools.PluginLogger;
import fr.moribus.imageonmap.ImageOnMap;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;

View File

@ -16,3 +16,12 @@ collect-data: true
# 0 means unlimited.
map-global-limit: 0
map-player-limit: 0
#Maximum size in pixels for an image to be. 0 is unlimited.
limit-map-size-x: 0
limit-map-size-y: 0
#Should the full image be saved when a map is rendered?
save-full-image: false

View File

@ -3,6 +3,7 @@ new: Creates a new ImageOnMap
delete: Deletes a map.
delete-noconfirm: Deletes a map. Deletion is permanent and made without confirmation
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.
explore: Opens a GUI to see and manage your maps.

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 @@
Lists another player's maps.