mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-11-16 23:25:11 +01:00
Merge pull request #186 from zDevelopers/fix/UUID_command
Fix UUIDs issues
This commit is contained in:
commit
ac51032e1a
@ -43,11 +43,27 @@ import fr.zcraft.quartzlib.components.commands.CommandException;
|
||||
import fr.zcraft.quartzlib.components.i18n.I;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
public abstract class IoMCommand extends Command {
|
||||
|
||||
|
||||
protected void retrieveUUID(String arg, Consumer<UUID> consumer) {
|
||||
UUID uuid;
|
||||
OfflinePlayer offlinePlayer;
|
||||
|
||||
offlinePlayer = Bukkit.getOfflinePlayer(arg);//If it is being removed we may have to use mojang services
|
||||
uuid = offlinePlayer.getUniqueId();
|
||||
|
||||
consumer.accept(uuid);
|
||||
|
||||
}
|
||||
|
||||
protected ImageMap getMapFromArgs() throws CommandException {
|
||||
return getMapFromArgs(playerSender(), 0, true);
|
||||
}
|
||||
|
@ -36,7 +36,6 @@
|
||||
|
||||
package fr.moribus.imageonmap.commands.maptool;
|
||||
|
||||
import fr.moribus.imageonmap.ImageOnMap;
|
||||
import fr.moribus.imageonmap.Permissions;
|
||||
import fr.moribus.imageonmap.commands.IoMCommand;
|
||||
import fr.moribus.imageonmap.map.ImageMap;
|
||||
@ -102,13 +101,7 @@ public class DeleteCommand extends IoMCommand {
|
||||
mapName = arguments.get(0);
|
||||
}
|
||||
|
||||
//TODO passer en static
|
||||
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
|
||||
if (uuid == null) {
|
||||
warning(sender, I.t("The player {0} does not exist.", playerName));
|
||||
return;
|
||||
}
|
||||
|
||||
retrieveUUID(playerName, uuid -> {
|
||||
ImageMap map = MapManager.getMap(uuid, mapName);
|
||||
|
||||
if (map == null) {
|
||||
|
@ -37,7 +37,6 @@
|
||||
package fr.moribus.imageonmap.commands.maptool;
|
||||
|
||||
|
||||
import fr.moribus.imageonmap.ImageOnMap;
|
||||
import fr.moribus.imageonmap.Permissions;
|
||||
import fr.moribus.imageonmap.commands.IoMCommand;
|
||||
import fr.moribus.imageonmap.gui.MapListGui;
|
||||
@ -45,6 +44,7 @@ import fr.zcraft.quartzlib.components.commands.CommandException;
|
||||
import fr.zcraft.quartzlib.components.commands.CommandInfo;
|
||||
import fr.zcraft.quartzlib.components.gui.Gui;
|
||||
import fr.zcraft.quartzlib.components.i18n.I;
|
||||
import fr.zcraft.quartzlib.tools.PluginLogger;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -52,7 +52,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
@CommandInfo(name = "explore",usageParameters = "[player name]")
|
||||
@CommandInfo(name = "explore", usageParameters = "[player name]")
|
||||
public class ExploreCommand extends IoMCommand {
|
||||
@Override
|
||||
protected void run() throws CommandException {
|
||||
@ -74,15 +74,11 @@ public class ExploreCommand extends IoMCommand {
|
||||
playerName = sender.getName();
|
||||
}
|
||||
|
||||
//TODO passer en static
|
||||
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
|
||||
if (uuid == null) {
|
||||
warning(sender, I.t("The player {0} does not exist.", playerName));
|
||||
return;
|
||||
}
|
||||
retrieveUUID(playerName, uuid -> {
|
||||
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
if (sender.isOnline()) {
|
||||
Gui.open(sender, new MapListGui(offlinePlayer,playerName));
|
||||
Gui.open(sender, new MapListGui(offlinePlayer, playerName));
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -82,16 +82,13 @@ public class GetCommand extends IoMCommand {
|
||||
|
||||
|
||||
|
||||
//TODO passer en static
|
||||
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
|
||||
|
||||
retrieveUUID(playerName, uuid -> {
|
||||
|
||||
if (!sender.isOnline()) {
|
||||
return;
|
||||
}
|
||||
if (uuid == null) {
|
||||
warning(sender, I.t("The player {0} does not exist.", playerName));
|
||||
return;
|
||||
}
|
||||
|
||||
ImageMap map = MapManager.getMap(uuid, mapName);
|
||||
|
||||
if (map == null) {
|
||||
|
@ -36,7 +36,6 @@
|
||||
|
||||
package fr.moribus.imageonmap.commands.maptool;
|
||||
|
||||
import fr.moribus.imageonmap.ImageOnMap;
|
||||
import fr.moribus.imageonmap.Permissions;
|
||||
import fr.moribus.imageonmap.commands.IoMCommand;
|
||||
import fr.moribus.imageonmap.map.ImageMap;
|
||||
@ -44,10 +43,7 @@ import fr.moribus.imageonmap.map.MapManager;
|
||||
import fr.zcraft.quartzlib.components.commands.CommandException;
|
||||
import fr.zcraft.quartzlib.components.commands.CommandInfo;
|
||||
import fr.zcraft.quartzlib.components.i18n.I;
|
||||
import fr.zcraft.quartzlib.tools.mojang.UUIDFetcher;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -106,42 +102,21 @@ public class GiveCommand extends IoMCommand {
|
||||
|
||||
final Player sender = playerSender();
|
||||
|
||||
//TODO passer en static
|
||||
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(from, uuid -> {
|
||||
if (uuid == null) {
|
||||
warning(sender, I.t("The player {0} does not exist.", from));
|
||||
return;
|
||||
}
|
||||
retrieveUUID(from, uuid -> {
|
||||
final ImageMap map = MapManager.getMap(uuid, mapName);
|
||||
|
||||
if (map == null) {
|
||||
warning(sender, I.t("This map does not exist."));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
UUID uuid2 = UUIDFetcher.fetch(playerName);
|
||||
if (uuid2 == null) {
|
||||
warning(sender, I.t("The player {0} does not exist.", playerName));
|
||||
return;
|
||||
}
|
||||
if (Bukkit.getPlayer((uuid2)) == null || !Bukkit.getPlayer((uuid2)).isOnline()) {
|
||||
warning(sender, I.t("The player {0} is not connected.", playerName));
|
||||
return;
|
||||
}
|
||||
|
||||
retrieveUUID(playerName, uuid2 -> {
|
||||
if (Bukkit.getPlayer((uuid2)) != null && Bukkit.getPlayer((uuid2)).isOnline()
|
||||
&& map.give(Bukkit.getPlayer(uuid2))) {
|
||||
info(I.t("The requested map was too big to fit in your inventory."));
|
||||
info(I.t("Use '/maptool getremaining' to get the remaining maps."));
|
||||
}
|
||||
|
||||
} catch (IOException | InterruptedException e) {
|
||||
try {
|
||||
throwInvalidArgument(I.t("The player {0} does not exist.", playerName));
|
||||
} catch (CommandException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -36,7 +36,6 @@
|
||||
|
||||
package fr.moribus.imageonmap.commands.maptool;
|
||||
|
||||
import fr.moribus.imageonmap.ImageOnMap;
|
||||
import fr.moribus.imageonmap.Permissions;
|
||||
import fr.moribus.imageonmap.commands.IoMCommand;
|
||||
import fr.moribus.imageonmap.map.ImageMap;
|
||||
@ -78,17 +77,9 @@ public class ListCommand extends IoMCommand {
|
||||
|
||||
final Player sender = playerSender();
|
||||
|
||||
//TODO passer en static
|
||||
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
|
||||
|
||||
retrieveUUID(playerName, uuid -> {
|
||||
List<ImageMap> mapList = MapManager.getMapList(uuid);
|
||||
if (uuid == null) {
|
||||
try {
|
||||
throwInvalidArgument(I.t("Player {} not found.", playerName));
|
||||
} catch (CommandException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mapList.isEmpty()) {
|
||||
info(sender, I.t("No map found."));
|
||||
return;
|
||||
|
@ -155,11 +155,9 @@ public class UpdateCommand extends IoMCommand {
|
||||
}
|
||||
|
||||
//TODO passer en static
|
||||
ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
|
||||
if (uuid == null) {
|
||||
warning(sender, I.t("The player {0} does not exist.", playerName));
|
||||
return;
|
||||
}
|
||||
//ImageOnMap.getPlugin().getCommandWorker().offlineNameFetch(playerName, uuid -> {
|
||||
retrieveUUID(playerName, uuid -> {
|
||||
|
||||
ImageMap map = MapManager.getMap(uuid, mapName);
|
||||
|
||||
if (map == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user