Skip to content

Commit

Permalink
Merge branch 'zDevelopers:indev' into indev
Browse files Browse the repository at this point in the history
  • Loading branch information
7man7LMYT authored Jun 27, 2021
2 parents ed14b3c + ac51032 commit b50da0b
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 87 deletions.
16 changes: 16 additions & 0 deletions src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,27 @@
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,13 +101,7 @@ protected void run() throws CommandException {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@
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;
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;
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 {
Expand All @@ -74,15 +74,11 @@ protected void run() throws CommandException {
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));
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,13 @@ protected void run() throws CommandException {



//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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@

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;
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;
Expand Down Expand Up @@ -106,42 +102,21 @@ protected void run() throws CommandException {

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;
}
});
});

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,17 +77,9 @@ protected void run() throws CommandException {

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ protected void run() throws CommandException {
}

//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) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/fr/moribus/imageonmap/ui/MapItemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
package fr.moribus.imageonmap.ui;

import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.PluginConfiguration;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap;
import fr.moribus.imageonmap.map.SingleMap;
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.core.QuartzLib;
import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.quartzlib.tools.items.ItemStackBuilder;
import fr.zcraft.quartzlib.tools.items.ItemUtils;
import fr.zcraft.quartzlib.tools.runners.RunTask;
Expand Down Expand Up @@ -260,7 +262,6 @@ private static void onItemFramePlace(ItemFrame frame, Player player, PlayerInter

frame.setItem(new ItemStack(Material.AIR));
if (SplatterMapManager.hasSplatterAttributes(mapItem)) {

if (!SplatterMapManager.placeSplatterMap(frame, player, event)) {
event.setCancelled(true); //In case of an error allow to cancel map placement
return;
Expand Down
22 changes: 4 additions & 18 deletions src/main/java/fr/moribus/imageonmap/ui/SplatterMapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
import fr.zcraft.quartzlib.components.i18n.I;
import fr.zcraft.quartzlib.components.nbt.NBT;
import fr.zcraft.quartzlib.components.nbt.NBTCompound;
import fr.zcraft.quartzlib.components.nbt.NBTException;
import fr.zcraft.quartzlib.components.nbt.NBTList;
import fr.zcraft.quartzlib.tools.PluginLogger;
import fr.zcraft.quartzlib.tools.items.GlowEffect;
import fr.zcraft.quartzlib.tools.items.ItemStackBuilder;
import fr.zcraft.quartzlib.tools.reflection.NMSException;
import fr.zcraft.quartzlib.tools.runners.RunTask;
Expand Down Expand Up @@ -125,22 +125,8 @@ public static ItemStack makeSplatterMap(PosterMap map) {
* @return The modified item stack. The instance may be different if the passed item stack is not a craft itemstack.
*/
public static ItemStack addSplatterAttribute(final ItemStack itemStack) {
try {
final NBTCompound nbt = NBT.fromItemStack(itemStack);
final NBTList enchantments = new NBTList();
final NBTCompound protection = new NBTCompound();

protection.put("id", "minecraft:mending");
protection.put("lvl", 1);
enchantments.add(protection);

nbt.put("Enchantments", enchantments);

return NBT.addToItemStack(itemStack, nbt, false);
} catch (NBTException | NMSException e) {
PluginLogger.error("Unable to set Splatter Map attribute on item", e);
return itemStack;
}
GlowEffect.addGlow(itemStack);
return itemStack;
}

/**
Expand Down Expand Up @@ -185,7 +171,7 @@ public static boolean isSplatterMap(ItemStack itemStack) {
* Return true if it has a specified splatter map
*
* @param player The player to check.
* @param map The map to check.
* @param map The map to check.
* @return True if the player has this map
*/
public static boolean hasSplatterMap(Player player, PosterMap map) {
Expand Down

0 comments on commit b50da0b

Please sign in to comment.