diff --git a/pom.xml b/pom.xml index 244e607..16f2bbd 100644 --- a/pom.xml +++ b/pom.xml @@ -156,24 +156,17 @@ 1.20.4-R0.1-SNAPSHOT provided + - org.bukkit - bukkit - 1.15.2-R0.1-SNAPSHOT + org.bstats + bstats-bukkit + 1.8 compile - fr.zcraft quartzlib 0.0.7-SNAPSHOT - - - org.bstats - bstats-bukkit - 1.8 - compile - diff --git a/src/main/java/fr/moribus/imageonmap/Argument.java b/src/main/java/fr/moribus/imageonmap/Argument.java index 2b9887b..b678a96 100644 --- a/src/main/java/fr/moribus/imageonmap/Argument.java +++ b/src/main/java/fr/moribus/imageonmap/Argument.java @@ -39,7 +39,9 @@ import fr.zcraft.quartzlib.tools.PluginLogger; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; @@ -50,7 +52,7 @@ public class Argument { private final Status status; private String content; - private String defaultValue; + private Object defaultValue; public Argument(String name, Type type, Status status) { this.name = name; @@ -108,19 +110,19 @@ public T getDefault() { } switch (type) { case BOOLEAN: - return (T) Boolean.valueOf(defaultValue); + return (T) Boolean.valueOf((Boolean) defaultValue); case INT: - return (T) Integer.getInteger(defaultValue); + return (T) Integer.getInteger((String) defaultValue); case UUID: - return (T) UUID.fromString(defaultValue); + return (T) UUID.fromString((String) defaultValue); case DOUBLE: - return (T) Double.valueOf(defaultValue); + return (T) Double.valueOf((String) defaultValue); case STRING: return (T) defaultValue; case ONLINE_PLAYER: - return (T) Bukkit.getPlayer(toUUID(defaultValue)); + return (T) Bukkit.getPlayer(toUUID((String) defaultValue)); case OFFLINE_PLAYER: - return (T) Bukkit.getOfflinePlayer(toUUID(defaultValue)); + return (T) Bukkit.getOfflinePlayer(toUUID((String) defaultValue)); default: PluginLogger.info("To be implemented"); @@ -232,7 +234,8 @@ public static boolean isAmbiguous(List prototype, boolean isPlayer) { return false; } - public static List parseArguments(List prototype, ArrayList args, boolean isPlayer) + public static Map parseArguments(List prototype, ArrayList args, + boolean isPlayer) throws Exception { //check if the command is not ambiguous if (isAmbiguous(prototype, isPlayer)) { @@ -240,7 +243,7 @@ public static List parseArguments(List prototype, ArrayList< } // givemap Vlammar Vlammar:"carte 1" 10 // string |string| string - List list = new ArrayList<>(); + Map map = new HashMap<>(); List uncertain = new ArrayList<>(); for (int i = 0; i < args.size(); i++) { @@ -250,13 +253,11 @@ public static List parseArguments(List prototype, ArrayList< for (int j = i; j < prototype.size(); j++) { PluginLogger.info("j = {0}", j); Argument a = prototype.get(j); - PluginLogger.info("argument name: \n{0}", a.toString()); switch (a.status) { - case OBLIGATORY: + case MANDATORY: PluginLogger.info("OBLIGATORY"); if (uncertain.isEmpty()) { - PluginLogger.info(a.getName()); - list.add(a); + map.put(a.getName(), a); a.setContent(arg); PluginLogger.info("argument : \n{0}", a.toString()); next = true; @@ -264,22 +265,18 @@ public static List parseArguments(List prototype, ArrayList< for (Argument l : uncertain) { //if size doesnt match or try { - PluginLogger.info("test pour l'erreur"); - PluginLogger.info(a.getContent()); a.setContent(a.content); //todo erreur ? - PluginLogger.info("argument : \n{0}", a.toString()); } catch (Exception e) { //shift to the right } } - PluginLogger.info(a.getName()); - list.add(a); + map.put(a.getName(), a); uncertain = new ArrayList<>(); } break; case OPTIONAL: - PluginLogger.info("OPTIONAL"); PluginLogger.info(a.getName()); + a.setContent(arg); uncertain.add(a); PluginLogger.info("argument : \n{0}", a.toString()); break; @@ -287,7 +284,7 @@ public static List parseArguments(List prototype, ArrayList< PluginLogger.info("OPTIONAL_FOR_PLAYER_ONLY"); if (!isPlayer) { PluginLogger.info(a.getName()); - list.add(a); + map.put(a.getName(), a); a.setContent(arg); PluginLogger.info("argument : \n{0}", a.toString()); next = true; @@ -308,7 +305,7 @@ public static List parseArguments(List prototype, ArrayList< } } } - return list; + return map; } @Override diff --git a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java index fcf3041..5ba86f1 100644 --- a/src/main/java/fr/moribus/imageonmap/ImageOnMap.java +++ b/src/main/java/fr/moribus/imageonmap/ImageOnMap.java @@ -43,6 +43,7 @@ import fr.moribus.imageonmap.commands.maptool.GetRemainingCommand; import fr.moribus.imageonmap.commands.maptool.GiveCommand; import fr.moribus.imageonmap.commands.maptool.ListCommand; +import fr.moribus.imageonmap.commands.maptool.MigrateCommand; import fr.moribus.imageonmap.commands.maptool.NewCommand; import fr.moribus.imageonmap.commands.maptool.RemotePlacingCommand; import fr.moribus.imageonmap.commands.maptool.RenameCommand; @@ -78,14 +79,11 @@ // rework des GUI (map part utile ???); // Pouvoir déployer carte à distance; // carte interractive (5.1?); -// bug: hover text ne marche plus; // glow effect a refaire (vraiment utile ???); // Miniature des maps en 1x1 (migration?); // ecrire directement sur les cartes pour ne pas tout perdre(migration); -// réduire dépendance QL; -// retirer les prints de QL et IoM => verbose ou debug pour avoir une trace de ce qui est fait ?; // bug: suppression image chat (inconnue ?) laisse item frame invisible; -// passer invisibiliter et glow dans le GUI si permission sinon solution RP avec le nombre qu'il faut de glowsac +// passer invisibiliter et glow dans le GUI si permission // avec un clic droit sur les frames et fenetre en verre pour la protection contre le grief des mobs et potion // invisibilité pour rendre frame invisible (peut etre que l'item utilisé pour le craft); proposer craft RP des cartes // soit avec un item map vide+ un item de peintre ? soit avec un atelier? @@ -160,7 +158,6 @@ public void onEnable() { return; } - saveDefaultConfig(); commandWorker = loadComponent(CommandWorkers.class); loadComponents(I18n.class, Gui.class, Commands.class, PluginConfiguration.class, ImageIOExecutor.class, @@ -184,7 +181,7 @@ public void onEnable() { GiveCommand.class, GetRemainingCommand.class, ExploreCommand.class, - //MigrateCommand.class,//Removed for now doesn't work nor is useful, maybe useful later on + MigrateCommand.class, UpdateCommand.class, RemotePlacingCommand.class ); diff --git a/src/main/java/fr/moribus/imageonmap/Status.java b/src/main/java/fr/moribus/imageonmap/Status.java index 5fcf49c..7e6a2c8 100644 --- a/src/main/java/fr/moribus/imageonmap/Status.java +++ b/src/main/java/fr/moribus/imageonmap/Status.java @@ -37,5 +37,5 @@ package fr.moribus.imageonmap; public enum Status { - OBLIGATORY, OPTIONAL, OPTIONAL_FOR_PLAYER_ONLY + MANDATORY, OPTIONAL, OPTIONAL_FOR_PLAYER_ONLY } diff --git a/src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java b/src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java index 8b8368d..5f48aa0 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/IoMCommand.java @@ -54,6 +54,7 @@ public abstract class IoMCommand extends Command { protected UUID getPlayerUUID(String playerName) { return Bukkit.getOfflinePlayer(playerName).getUniqueId(); + //TODO replace with homemade solution using https://api.mojang.com/users/profiles/minecraft/ } private boolean checkTooArguments(boolean bool, String msg) throws CommandException { @@ -72,6 +73,7 @@ protected boolean checkTooFewArguments(boolean bool) throws CommandException { } protected boolean checkArguments(boolean bool1, boolean bool2) throws CommandException { + //TODO WTF is happening here return !(checkTooManyArguments(bool1) || checkTooFewArguments(bool2)); } diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreCommand.java index 55085e1..4551a76 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/ExploreCommand.java @@ -74,6 +74,8 @@ protected void run() throws CommandException { } OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(playerName); + //TODO replace with homemade solution using https://api.mojang.com/users/profiles/minecraft/playername + // to get the UUId if (sender.isOnline()) { Gui.open(sender, new PosterListGui(offlinePlayer, playerName)); } diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/GiveCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/GiveCommand.java index 408efc8..046f9c4 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/GiveCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/GiveCommand.java @@ -49,6 +49,7 @@ import fr.zcraft.quartzlib.tools.PluginLogger; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -58,9 +59,9 @@ @CommandInfo(name = "give", usageParameters = " [playerFrom]: [quantity]") public class GiveCommand extends IoMCommand { protected List commandPrototype() { - Argument target = new Argument("target", Type.STRING, Status.OBLIGATORY); + Argument target = new Argument("target", Type.STRING, Status.MANDATORY); Argument from = new Argument("from", Type.STRING, Status.OPTIONAL_FOR_PLAYER_ONLY); - Argument posterName = new Argument("posterName", Type.STRING, Status.OBLIGATORY); + Argument posterName = new Argument("posterName", Type.STRING, Status.MANDATORY); Argument quantity = new Argument("quantity", Type.INT, Status.OPTIONAL, "1"); List list = new ArrayList<>(); @@ -79,10 +80,17 @@ protected void run() throws CommandException { List cmdProto = commandPrototype(); ArrayList arguments = getArgs(); - Boolean isPlayer = sender != null; - List args; + boolean isPlayer = sender != null; + final String posterName; + final String from; + final String playerName; + final int quantity; try { - args = Argument.parseArguments(cmdProto, arguments, isPlayer); + Map argMap = Argument.parseArguments(cmdProto, arguments, isPlayer); + posterName = argMap.get("posterName").getContent(); + from = argMap.get("from").getContent(); + playerName = argMap.get("target").getContent(); + quantity = argMap.get("quantity").getContent(); } catch (Exception e) { PluginLogger.error("Error while parsing command"); return; @@ -95,11 +103,12 @@ protected void run() throws CommandException { return; } + /* final String posterName = Argument.findContent("posterName", args); final String from = Argument.findContent("from", args); final String playerName = Argument.findContent("target", args); final int quantity = Argument.findContent("quantity", args); - + */ PluginLogger.info("quantity {0}", quantity); if (posterName == null || from == null || playerName == null) { PluginLogger.error("Error one argument is null, check argument names"); diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java index be968de..59f21fb 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/ListCommand.java @@ -36,7 +36,10 @@ package fr.moribus.imageonmap.commands.maptool; +import fr.moribus.imageonmap.Argument; import fr.moribus.imageonmap.Permissions; +import fr.moribus.imageonmap.Status; +import fr.moribus.imageonmap.Type; import fr.moribus.imageonmap.commands.IoMCommand; import fr.moribus.imageonmap.map.ImagePoster; import fr.moribus.imageonmap.map.PosterManager; @@ -49,7 +52,11 @@ import fr.zcraft.quartzlib.tools.PluginLogger; import fr.zcraft.quartzlib.tools.text.RawMessage; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -70,6 +77,7 @@ protected void run() throws CommandException { String playerName; final boolean isHuman = (sender instanceof Player); + if (arguments.size() == 1) { if (!Permissions.LISTOTHER.grantedTo(sender) && isHuman) { throwNotAuthorized(); @@ -85,6 +93,19 @@ protected void run() throws CommandException { return; } } + try { + List prototype = new ArrayList<>(); + prototype.add(new Argument("playerName", Type.STRING, Status.OPTIONAL, playerName)); + Map argMap = Argument.parseArguments(prototype, arguments, isHuman); + + for (String key : argMap.keySet()) { + Argument arg = argMap.get(key); + PluginLogger.info("Arguments : \n name " + arg.getName() + "\n type " + arg.getType() + + "\n status " + arg.getStatus()); + } + } catch (Exception e) { + PluginLogger.warning(e.toString()); + } final Player playerSender; if (isHuman) { playerSender = playerSender(); @@ -102,6 +123,7 @@ protected void run() throws CommandException { } return; } + String msg = I.tn("{white}{bold}{0} map found.", "{white}{bold}{0} maps found.", posterList.size()); diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/NewCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/NewCommand.java index a2a2d1d..4068e11 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/NewCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/NewCommand.java @@ -36,9 +36,11 @@ package fr.moribus.imageonmap.commands.maptool; +import fr.moribus.imageonmap.Argument; import fr.moribus.imageonmap.Permissions; +import fr.moribus.imageonmap.Status; +import fr.moribus.imageonmap.Type; import fr.moribus.imageonmap.commands.IoMCommand; -import fr.moribus.imageonmap.gui.RenderGui; import fr.moribus.imageonmap.image.ImageRendererExecutor; import fr.moribus.imageonmap.image.ImageUtils; import fr.moribus.imageonmap.map.ImagePoster; @@ -47,15 +49,15 @@ import fr.moribus.imageonmap.map.PosterMap; 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.components.worker.WorkerCallback; import fr.zcraft.quartzlib.tools.PluginLogger; -import fr.zcraft.quartzlib.tools.text.ActionBar; -import fr.zcraft.quartzlib.tools.text.MessageSender; -import java.net.MalformedURLException; import java.net.URL; -import org.bukkit.ChatColor; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -126,64 +128,89 @@ private PosterData parseSize(PosterData posterData) { @Override protected void run() throws CommandException { - //TODO check if not too many args - final Player player = playerSender(); - if (args.length < 1) { - throwInvalidArgument(I.t("You must give an URL to take the image from.")); - } - //Checking if the poster limit and image limit - - imageLimitReached(player); - posterLimitReached(player); - PosterData posterData; try { - posterData = new PosterData(new URL(args[0])); + //TODO check if not too many args + final Player player = playerSender(); + if (args.length < 1) { + throwInvalidArgument(I.t("You must give an URL to take the image from.")); + } + //Checking if the poster limit and image limit + + imageLimitReached(player); + posterLimitReached(player); + boolean isPlayer = sender != null; + ArrayList arguments = getArgs(); + + + List prototype = new ArrayList<>(); + prototype.add(new Argument("URL", Type.STRING, Status.MANDATORY)); + Map argMap = Argument.parseArguments(prototype, arguments, isPlayer); + for (String key : argMap.keySet()) { + Argument arg = argMap.get(key); + PluginLogger.info("Arguments : \n name " + arg.getName() + "\n type " + arg.getType() + + "\n status " + arg.getStatus() + "\n arg content " + arg.getContent()); + } + + PluginLogger.info("qjksckhjkhqjskhjc quhshukchjkqs " + argMap.get("URL").getContent()); + URL url = new URL(argMap.get("URL").getContent()); + PosterData posterData = new PosterData(url); + posterData.setURL(url); //TODO WTF... the constructor doesn't work + PluginLogger.info("url qsjkh jsjc " + url); + + if (!Permissions.BYPASS_WHITELIST.grantedTo(player) && !checkHostnameWhitelist(posterData.getURL())) { throwInvalidArgument(I.t("This hosting website is not trusted, if you think that this is an error " + " contact your server administrator")); return; } - } catch (MalformedURLException ex) { - throwInvalidArgument(I.t("Invalid URL.")); - return; - } - boolean isPlayer = sender != null; - // TODO Add a per-player toggle for the GUI. - if (args.length < 2 && isPlayer) { - try { - ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("test...")); - } catch (Exception e) { - PluginLogger.info("Exception " + e); - } + // TODO Add a per-player toggle for the GUI. + if (args.length < 2 && isPlayer) { + try { + String message = I.t("&1 test..."); + PluginLogger.info("URL quuhqsjhkcjhk " + posterData.getURL()); + TextComponent text = new TextComponent(message); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, text); + posterData.setHeight(0); + posterData.setWidth(0); + posterData.setScaling(ImageUtils.ScalingType.NONE); + } catch (Exception e) { + PluginLogger.info("Exception " + e.getMessage()); + } - //Gui.open(player, new RenderGui(posterData.getURL()); - //ImageRendererExecutor.renderAndNotify(posterData.getURL(), scaling, player.getUniqueId(), width, height); - } else { - if (args.length >= 2) { - if (args.length >= 3) { - try { - posterData = parseSize(posterData); - } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { - throwInvalidArgument(I.t("resize dimension as to be in format or or .")); - return; + //Gui.open(player, new RenderGui(posterData.getURL()); + //ImageRendererExecutor.renderAndNotify(posterData.getURL(), posterData.getScaling(), + // player.getUniqueId(), + //posterData.getWidth(), posterData.getHeight()); + } else { + if (args.length >= 2) { + if (args.length >= 3) { + try { + posterData = parseSize(posterData); + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + throwInvalidArgument( + I.t("resize dimension as to be in format or or .")); + return; + } } + posterData.setScaling(resizeMode()); + } + if (posterData.getWidth() < 0 || posterData.getWidth() > 256 + || posterData.getHeight() < 0 || posterData.getHeight() > 256) { + throwInvalidArgument(I.t("You need to specify a valid size. e.g. resize 4 5")); + return; } - posterData.setScaling(resizeMode()); - } - if (posterData.getWidth() < 0 || posterData.getWidth() > 256 - || posterData.getHeight() < 0 || posterData.getHeight() > 256) { - throwInvalidArgument(I.t("You need to specify a valid size. e.g. resize 4 5")); - return; } try { - ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("Rendering...")); + String message = I.t("&1 Rendering..."); + TextComponent text = new TextComponent(message); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, text); ImageRendererExecutor.render(posterData, player.getUniqueId(), new WorkerCallback() { @Override public void finished(ImagePoster result) { - ActionBar.removeMessage(player); - MessageSender.sendActionBarMessage(player, - ChatColor.DARK_GREEN + I.t("Rendering finished!")); + String message = I.t("&1 Rendering finished!"); + TextComponent text = new TextComponent(message); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, text); if (result.give(player) && (result instanceof PosterMap && !((PosterMap) result).hasColumnData())) { @@ -203,9 +230,14 @@ public void errored(Throwable exception) { } }); } finally { - ActionBar.removeMessage(player); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("")); } + + } catch (Exception e) { + PluginLogger.warning(e.toString()); + throwInvalidArgument(I.t("Invalid URL.")); } + } @Override diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/RemotePlacingCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/RemotePlacingCommand.java index 1990790..ae78523 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/RemotePlacingCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/RemotePlacingCommand.java @@ -38,14 +38,82 @@ import fr.moribus.imageonmap.Permissions; import fr.moribus.imageonmap.commands.IoMCommand; +import fr.moribus.imageonmap.map.ImagePoster; +import fr.moribus.imageonmap.map.PlayerPosterStore; +import fr.moribus.imageonmap.map.PosterManager; +import fr.moribus.imageonmap.map.PosterMap; import fr.zcraft.quartzlib.components.commands.CommandException; import fr.zcraft.quartzlib.components.commands.CommandInfo; +import fr.zcraft.quartzlib.components.i18n.I; +import java.util.ArrayList; +import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.BlockFace; import org.bukkit.command.CommandSender; +import org.bukkit.entity.ItemFrame; -@CommandInfo(name = "RemotePlacing", usageParameters = "[player name]:map name position rotation") +@CommandInfo(name = "RemotePlacing", usageParameters = "[player name]:mapName worldname x y z [N|W|S|E]") public class RemotePlacingCommand extends IoMCommand { @Override protected void run() throws CommandException { + ArrayList arguments = getArgs(); + String playerName; + String mapName; + if (arguments.get(1).contains(":")) { + playerName = arguments.get(1).split(":")[0]; + mapName = arguments.get(1).split(":")[1]; + } else { + playerName = playerSender().getName(); + mapName = arguments.get(1); + } + UUID uuid = Bukkit.getOfflinePlayer(playerName).getUniqueId(); + ImagePoster poster = PosterManager.getplayerPosterStore(uuid).getPoster(mapName); + + String worldName = arguments.get(1); + World world = Bukkit.getWorld(worldName); + Location loc = new Location(world, + Integer.parseInt(arguments.get(2)), + Integer.parseInt(arguments.get(3)), + Integer.parseInt(arguments.get(4))); + BlockFace bf = null; + //TODO add ground placement and bf for ground ceilling and wall + switch (arguments.get(5)) { + case "N": + case "n": + case "North": + case "north": + bf = BlockFace.NORTH; + break; + case "E": + case "e": + case "East": + case "east": + bf = BlockFace.EAST; + break; + case "W": + case "w": + case "West": + case "west": + bf = BlockFace.WEST; + break; + case "S": + case "s": + case "South": + case "south": + bf = BlockFace.SOUTH; + break; + default: + //or messagesender + throwInvalidArgument(I.t("Must specify a valid rotation N|W|S|E|")); + break; + } + ItemFrame i = world.spawn(loc, ItemFrame.class); + i.setFacingDirection(bf); + world.getBlockAt(loc); + + //summon item frame(location, rotation) //if wall => need position and direction N/S/E/W //else if floor or ceiling => same + rotation } @@ -54,4 +122,5 @@ protected void run() throws CommandException { public boolean canExecute(CommandSender sender) { return Permissions.REMOTE_PLACING.grantedTo(sender); } + } diff --git a/src/main/java/fr/moribus/imageonmap/commands/maptool/UpdateCommand.java b/src/main/java/fr/moribus/imageonmap/commands/maptool/UpdateCommand.java index 2870e92..f1dfcc9 100644 --- a/src/main/java/fr/moribus/imageonmap/commands/maptool/UpdateCommand.java +++ b/src/main/java/fr/moribus/imageonmap/commands/maptool/UpdateCommand.java @@ -47,13 +47,12 @@ import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.components.worker.WorkerCallback; import fr.zcraft.quartzlib.tools.PluginLogger; -import fr.zcraft.quartzlib.tools.text.ActionBar; -import fr.zcraft.quartzlib.tools.text.MessageSender; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.UUID; -import org.bukkit.ChatColor; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -169,8 +168,10 @@ protected void run() throws CommandException { try { String msg = I.t("Updating..."); if (playerSender != null) { - //TODO tester si player humain - ActionBar.sendPermanentMessage(playerSender, ChatColor.DARK_GREEN + msg); + //TODO test if player human + String message = I.t("&2 Updating..."); + TextComponent text = new TextComponent(message); + playerSender.spigot().sendMessage(ChatMessageType.ACTION_BAR, text); } else { PluginLogger.info(msg); } @@ -180,10 +181,9 @@ protected void run() throws CommandException { public void finished(ImagePoster result) { String msg = I.t("The map was updated using the new image!"); if (playerSender != null) { - //TODO tester si player humain - ActionBar.removeMessage(playerSender); - MessageSender.sendActionBarMessage(playerSender, - ChatColor.DARK_GREEN + msg); + String message = I.t("&2 The map was updated using the new image!"); + TextComponent text = new TextComponent(message); + playerSender.spigot().sendMessage(ChatMessageType.ACTION_BAR, text); } else { PluginLogger.info(msg); } @@ -192,9 +192,9 @@ public void finished(ImagePoster result) { @Override public void errored(Throwable exception) { if (playerSender != null) { - playerSender - .sendMessage( - I.t("{ce}Map rendering failed: {0}", exception.getMessage())); + String message = I.t("&C Map rendering failed: {0}", exception.getMessage()); + TextComponent text = new TextComponent(message); + playerSender.spigot().sendMessage(ChatMessageType.CHAT, text); } PluginLogger.warning("Rendering from {0} failed: {1}: {2}", playerSender.getName(), @@ -204,7 +204,7 @@ public void errored(Throwable exception) { }); } finally { if (playerSender != null) { - ActionBar.removeMessage(playerSender); + playerSender.spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent("")); } } } catch (MalformedURLException | CommandException ex) { diff --git a/src/main/java/fr/moribus/imageonmap/gui/PosterDetailGui.java b/src/main/java/fr/moribus/imageonmap/gui/PosterDetailGui.java index 7ea03af..ec240b0 100644 --- a/src/main/java/fr/moribus/imageonmap/gui/PosterDetailGui.java +++ b/src/main/java/fr/moribus/imageonmap/gui/PosterDetailGui.java @@ -36,7 +36,6 @@ package fr.moribus.imageonmap.gui; -import static fr.zcraft.quartzlib.tools.reflection.Reflection.getFieldValue; import fr.moribus.imageonmap.Permissions; import fr.moribus.imageonmap.map.ImagePoster; @@ -69,25 +68,12 @@ public PosterDetailGui(ImagePoster iposter, OfflinePlayer p, String name) { this.name = name; } - private void setPosterPartCustomModelData(ItemStack item, int x, int y) { - int id = 1000; + private void setPosterPartCustomModelData(ItemStack item) { ItemMeta meta = item.getItemMeta(); - - String posterId = iposter.getId(); //TODO make it prettier and fix issues with scrolling if (iposter instanceof PosterMap) { - PosterMap poster = ((PosterMap) iposter); - int columnCount = poster.getColumnCount(); - int rowCount = poster.getRowCount(); - if (columnCount == 0 && rowCount == 0) { - id = 1008; - } - if (x == 0 && y == 0 && columnCount > 0 && rowCount > 0) { - id = 1001; - } - - meta.setCustomModelData(1000); + meta.setCustomModelData(1000);//TODO ID was 1000 maybe a bug there to check item.setItemMeta(meta); } } @@ -97,9 +83,8 @@ protected ItemStack getViewItem(int x, int y) { final Material partMaterial = y % 2 == x % 2 ? Material.MAP : Material.PAPER; ItemStackBuilder builder = new ItemStackBuilder(partMaterial); ItemStack itemStack = builder.craftItem(); - PluginLogger.info("before setmappart"); - setPosterPartCustomModelData(itemStack, x, y); + setPosterPartCustomModelData(itemStack); builder = new ItemStackBuilder(itemStack); builder = builder .title(I.t(getPlayerLocale(), "{green}Map part")) @@ -253,7 +238,6 @@ public void rename() { if (getParent() != null) { RunTask.later(() -> Gui.open(getPlayer(), this), 1L); - } else { close(); } diff --git a/src/main/java/fr/moribus/imageonmap/gui/PosterListGui.java b/src/main/java/fr/moribus/imageonmap/gui/PosterListGui.java index d46f610..e3b0ac2 100644 --- a/src/main/java/fr/moribus/imageonmap/gui/PosterListGui.java +++ b/src/main/java/fr/moribus/imageonmap/gui/PosterListGui.java @@ -154,7 +154,7 @@ protected ItemStack getPickedUpItem(ImagePoster iposter) { PosterMap poster = (PosterMap) iposter; if (poster.hasColumnData()) { - return SplatterPosterManager.makeSplatterPoster((PosterMap) poster); + return SplatterPosterManager.makeSplatterPoster(poster); } PosterItemManager.giveParts(getPlayer(), poster); diff --git a/src/main/java/fr/moribus/imageonmap/image/ImageRendererExecutor.java b/src/main/java/fr/moribus/imageonmap/image/ImageRendererExecutor.java index 9ea0c1b..fe8f348 100644 --- a/src/main/java/fr/moribus/imageonmap/image/ImageRendererExecutor.java +++ b/src/main/java/fr/moribus/imageonmap/image/ImageRendererExecutor.java @@ -49,8 +49,6 @@ import fr.zcraft.quartzlib.components.worker.WorkerCallback; import fr.zcraft.quartzlib.components.worker.WorkerRunnable; import fr.zcraft.quartzlib.tools.PluginLogger; -import fr.zcraft.quartzlib.tools.text.ActionBar; -import fr.zcraft.quartzlib.tools.text.MessageSender; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; @@ -61,8 +59,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.Future; import javax.imageio.ImageIO; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -74,25 +73,29 @@ public static void renderAndNotify(final URL url, final ImageUtils.ScalingType s if (player == null) { return; } - - ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("Rendering...")); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(I.t("&1 Rendering..."))); render(url, scaling, player.getUniqueId(), width, height, new WorkerCallback() { @Override public void finished(ImagePoster result) { - ActionBar.removeMessage(player); - MessageSender.sendActionBarMessage(player, ChatColor.DARK_GREEN + I.t("Rendering finished!")); + String message = I.t("&1 Rendering finished!"); + TextComponent text = new TextComponent(message); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, text); if (result.give(player) && (result instanceof PosterMap && !((PosterMap) result).hasColumnData())) { - player.sendMessage(ChatColor.GRAY + I.t("The rendered map was too big to fit in your inventory.")); - player.sendMessage(ChatColor.GRAY + I.t("Use '/maptool getremaining' to get the remaining maps.")); + player.spigot().sendMessage(ChatMessageType.CHAT, + new TextComponent(I.t("&7 The rendered map was too big to fit in your inventory."))); + player.spigot().sendMessage(ChatMessageType.CHAT, + new TextComponent(I.t("&7 Use '/maptool getremaining' to get the remaining maps."))); } } @Override public void errored(Throwable exception) { - ActionBar.removeMessage(player); - player.sendMessage(I.t("{ce}Map rendering failed: {0}", exception.getMessage())); + String message = I.t("&C Map rendering failed: {0}", exception.getMessage()); + TextComponent text = new TextComponent(message); + player.spigot().sendMessage(ChatMessageType.CHAT, text); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("")); PluginLogger.warning("Rendering from {0} failed: {1}: {2}", player.getName(), diff --git a/src/main/java/fr/moribus/imageonmap/image/Renderer.java b/src/main/java/fr/moribus/imageonmap/image/Renderer.java index dd889c7..68b9f55 100644 --- a/src/main/java/fr/moribus/imageonmap/image/Renderer.java +++ b/src/main/java/fr/moribus/imageonmap/image/Renderer.java @@ -37,10 +37,12 @@ package fr.moribus.imageonmap.image; import fr.zcraft.quartzlib.tools.PluginLogger; +import java.awt.Color; import java.awt.image.BufferedImage; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.map.MapCanvas; +import org.bukkit.map.MapPalette; import org.bukkit.map.MapRenderer; import org.bukkit.map.MapView; diff --git a/src/main/java/fr/moribus/imageonmap/ui/PosterItemManager.java b/src/main/java/fr/moribus/imageonmap/ui/PosterItemManager.java index d498a6b..8f196a8 100644 --- a/src/main/java/fr/moribus/imageonmap/ui/PosterItemManager.java +++ b/src/main/java/fr/moribus/imageonmap/ui/PosterItemManager.java @@ -103,11 +103,9 @@ public static boolean give(Player player, PosterMap poster) { private static boolean give(final Player player, final ItemStack item) { boolean given = ItemUtils.give(player, item); - //TODO simplify this if (given) { player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 1, 1); } - return !given; } @@ -206,8 +204,8 @@ private static String getPosterTitle(ItemStack item) { * Returns the item to place to display the (col;row) part of the given poster. * * @param poster The map to take the part from. - * @param x The x coordinate of the part to display. Starts at 0. - * @param y The y coordinate of the part to display. Starts at 0. + * @param x The x coordinate of the part to display. Starts at 0. + * @param y The y coordinate of the part to display. Starts at 0. * @return The map. * @throws ArrayIndexOutOfBoundsException If x;y is not inside the map. */ @@ -254,7 +252,7 @@ private static void onItemFramePlace(ItemFrame frame, Player player, PlayerInter frame.setItem(new ItemStack(Material.AIR)); if (SplatterPosterManager.hasSplatterAttributes(posterItem)) { - if (!SplatterPosterManager.placeSplatterPoster(frame, player, event)) { + if (!SplatterPosterManager.placeSplatterPoster(frame, player)) { event.setCancelled(true); //In case of an error allow to cancel map placement return; @@ -308,7 +306,7 @@ private static void onItemFrameRemove(ItemFrame frame, Player player, EntityDama if (!PosterManager.managesPoster(frame.getItem())) { return; } - SplatterPosterManager.removePropertiesFromFrames(player, frame); + SplatterPosterManager.removePropertiesFromFrames(frame); frame.setItem(new ItemStackBuilder(item) .title(getPosterTitle(item)) .hideAllAttributes() diff --git a/src/main/java/fr/moribus/imageonmap/ui/SplatterPosterManager.java b/src/main/java/fr/moribus/imageonmap/ui/SplatterPosterManager.java index 70dec0b..ade2d0e 100644 --- a/src/main/java/fr/moribus/imageonmap/ui/SplatterPosterManager.java +++ b/src/main/java/fr/moribus/imageonmap/ui/SplatterPosterManager.java @@ -45,10 +45,8 @@ import fr.zcraft.quartzlib.components.i18n.I; import fr.zcraft.quartzlib.tools.PluginLogger; import fr.zcraft.quartzlib.tools.items.ItemStackBuilder; -import fr.zcraft.quartzlib.tools.text.MessageSender; import fr.zcraft.quartzlib.tools.world.FlatLocation; import fr.zcraft.quartzlib.tools.world.WorldUtils; -import java.lang.reflect.Method; import java.util.Map; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; @@ -58,6 +56,7 @@ import org.bukkit.Material; import org.bukkit.Rotation; import org.bukkit.block.BlockFace; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.ItemFrame; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerInteractEntityEvent; @@ -126,8 +125,8 @@ public static ItemStack makeSplatterPoster(PosterMap poster) { * @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) { - //GlowEffect.addGlow(itemStack); - //TODO find a good solution there without using QL + itemStack.addUnsafeEnchantment(Enchantment.LURE, 1); + //TODO ADD event to forbid xp duplication and usage in crafting table return itemStack; } @@ -170,7 +169,7 @@ public static boolean hasSplatterPoster(Player player, PosterMap poster) { * @return true if the map was correctly placed */ @SuppressWarnings("checkstyle:VariableDeclarationUsageDistance") - public static boolean placeSplatterPoster(ItemFrame startFrame, Player player, PlayerInteractEntityEvent event) { + public static boolean placeSplatterPoster(ItemFrame startFrame, Player player) { ImagePoster iposter = PosterManager.getPoster(player.getInventory().getItemInMainHand()); if (!(iposter instanceof PosterMap)) { return false; @@ -190,17 +189,15 @@ public static boolean placeSplatterPoster(ItemFrame startFrame, Player player, P surface.loc2 = endLocation; if (!surface.isValid(player)) { - MessageSender.sendActionBarMessage(player, - I.t("{ce}There is not enough space to place this map ({0} × {1}).", - poster.getColumnCount(), - poster.getRowCount())); - - + String message = + I.t("§c There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(), + poster.getRowCount()); + TextComponent text = new TextComponent(message); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, text); return false; } Rotation r = Rotation.NONE; BlockFace bf = WorldUtils.get4thOrientation(player.getLocation()); - PluginLogger.info("bf " + bf); PluginLogger.info("YAW calc {0} YAW {1} ", Math.abs(player.getLocation().getYaw()) - 180f, player.getLocation().getYaw()); switch (bf) { @@ -226,7 +223,6 @@ public static boolean placeSplatterPoster(ItemFrame startFrame, Player player, P bf = WorldUtils.get4thOrientation(player.getLocation()); int id = poster.getPosterIdAtReverseZ(i, bf, startFrame.getFacing()); - PluginLogger.info("toto"); switch (frame.getFacing()) { case UP: break; @@ -264,9 +260,6 @@ public static boolean placeSplatterPoster(ItemFrame startFrame, Player player, P FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing()); FlatLocation endLocation = startLocation.clone().add(poster.getColumnCount(), poster.getRowCount()); - PluginLogger.info(startLocation.toString()); - PluginLogger.info(endLocation.toString()); - wall.loc1 = startLocation; wall.loc2 = endLocation; @@ -275,7 +268,8 @@ public static boolean placeSplatterPoster(ItemFrame startFrame, Player player, P String message = I.t("§c There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(), poster.getRowCount()); - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message)); + TextComponent text = new TextComponent(message); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, text); return false; } @@ -307,11 +301,6 @@ public void run() { frame.setItem(item); } }, 5L); - /*RunTask.later(() -> { - addPropertiesToFrames(player, frame); - ItemStack item = PosterItemManager.createPosterItem(id, "", true, false); - frame.setItem(item); - }, 5L);*/ } /** @@ -332,7 +321,6 @@ public static PosterMap removeSplatterPoster(ItemFrame startFrame, Player player } //We search for the map on the top left corner Location startingLocation = poster.findLocationFirstFrame(startFrame, player); - PluginLogger.info("remove splater " + startingLocation); Map itemFrameLocations = PosterOnASurface.getItemFramesLocation(player, startingLocation, startFrame.getLocation(), @@ -342,7 +330,7 @@ public static PosterMap removeSplatterPoster(ItemFrame startFrame, Player player for (Map.Entry entry : itemFrameLocations.entrySet()) { ItemFrame frame = itemFrameLocations.get(entry.getKey()); if (frame != null) { - removePropertiesFromFrames(player, frame); + removePropertiesFromFrames(frame); frame.setItem(null); } } @@ -352,21 +340,11 @@ public static PosterMap removeSplatterPoster(ItemFrame startFrame, Player player public static void addPropertiesToFrames(Player player, ItemFrame frame) { if (Permissions.PLACE_INVISIBLE_SPLATTER_POSTER.grantedTo(player)) { - try { - Method setVisible = frame.getClass().getMethod("setVisible", boolean.class); - setVisible.invoke(frame, false); - } catch (Exception e) { - //1.16- - } + frame.setVisible(false); } } - public static void removePropertiesFromFrames(Player player, ItemFrame frame) { - try { - Method setVisible = frame.getClass().getMethod("setVisible", boolean.class); - setVisible.invoke(frame, true); - } catch (Exception e) { - //1.16- - } + public static void removePropertiesFromFrames(ItemFrame frame) { + frame.setVisible(true); } }