mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-11-16 07:05:14 +01:00
added prefix player and uuid
This commit is contained in:
parent
a41f0359ce
commit
f5e0ea9a79
@ -43,30 +43,88 @@ import fr.moribus.imageonmap.map.MapManager;
|
|||||||
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 fr.zcraft.zlib.tools.PluginLogger;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
||||||
|
@CommandInfo(name = "give", usageParameters = "<Player> <MapName> or <Player> <MapName> <Player where to find the map>")
|
||||||
|
public class GiveCommand extends IoMCommand {
|
||||||
|
/**
|
||||||
|
* Parse an argument given at a specific index, it will return a player depending on the given prefixe. Can be player:<username> or uuid:<uuid>
|
||||||
|
*
|
||||||
|
* @param index The index.
|
||||||
|
* @return The retrieved player.
|
||||||
|
* @throws CommandException If the value is invalid.
|
||||||
|
* @throws InterruptedException .
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private OfflinePlayer parse(int index) throws CommandException {
|
||||||
|
|
||||||
|
String s = args[index].trim();
|
||||||
|
|
||||||
|
String[] subs = s.split(":");
|
||||||
|
try {
|
||||||
|
//
|
||||||
|
if (subs.length == 1) {
|
||||||
|
return getOfflinePlayerParameter(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (subs[0]) {
|
||||||
|
case "player":
|
||||||
|
return getOfflinePlayerParameter(subs[1]);
|
||||||
|
|
||||||
|
case "uuid":
|
||||||
|
StringBuffer string = new StringBuffer(subs[1].toLowerCase());
|
||||||
|
//if there are no '-'
|
||||||
|
if (string.length() == 32) {
|
||||||
|
//we try to fix it by adding - at pos 8,12,16,20
|
||||||
|
Integer[] pos={20,16,12,8};
|
||||||
|
for(int i:pos)
|
||||||
|
string = string.insert(i, "-");
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the given uuid is well formed with 8-4-4-4-12 = 36 chars in length (including '-')
|
||||||
|
if (string.length() == 36)
|
||||||
|
return Bukkit.getOfflinePlayer(UUID.fromString(string.toString()));
|
||||||
|
|
||||||
|
throwInvalidArgument(I.t("Invalid uuid, please provide an uuid of this form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx or xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
|
||||||
|
|
||||||
|
case "bank":
|
||||||
|
throwInvalidArgument(I.t("Not supported yet"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throwInvalidArgument(I.t("Invalid prefix, valid one are: player | uuid"));
|
||||||
|
}
|
||||||
|
} catch (InterruptedException | IOException e) {
|
||||||
|
PluginLogger.warning(I.t("Can't access to mojang API to check the player UUID"));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@CommandInfo (name = "give", usageParameters = "<Player> <MapName> or <Player> <MapName> <Player where to find the map>")
|
|
||||||
public class GiveCommand extends IoMCommand
|
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
protected void run() throws CommandException
|
protected void run() throws CommandException {
|
||||||
{
|
|
||||||
if(args.length < 2) throwInvalidArgument(I.t("You must give a valid player name and a map name."));
|
if (args.length < 2) throwInvalidArgument(I.t("You must give a valid player name and a map name."));
|
||||||
|
|
||||||
final Player p = getPlayerParameter(0);
|
final Player p = getPlayerParameter(0);
|
||||||
|
|
||||||
ImageMap map;
|
ImageMap map;
|
||||||
//TODO does not support map name with space
|
//TODO add support for map name with spaces "cool name" or name or "name" "cool name with a \" and some stuff" should work
|
||||||
Player player=null;
|
OfflinePlayer player = null;
|
||||||
if(args.length<4) {
|
|
||||||
|
if (args.length < 4) {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
player = playerSender();
|
player = playerSender();
|
||||||
}
|
}
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
player = getPlayerParameter(2);
|
player = parse(2);
|
||||||
}
|
}
|
||||||
map = MapManager.getMap(player.getUniqueId(), args[1]);
|
map = MapManager.getMap(player.getUniqueId(), args[1]);
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
@ -77,8 +135,7 @@ public class GiveCommand extends IoMCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canExecute(CommandSender sender)
|
public boolean canExecute(CommandSender sender) {
|
||||||
{
|
|
||||||
return Permissions.GIVE.grantedTo(sender);
|
return Permissions.GIVE.grantedTo(sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user