diff --git a/README.MD b/README.MD index 6192970..7d94502 100644 --- a/README.MD +++ b/README.MD @@ -5,6 +5,8 @@ by rendering them onto maps and placing them in item frames. This can be used to create info graphics, custom paintings and even the appearance of custom textures. +![Example Screenshot](./screenshot.png) + ## Installation You will need a Server that implements Bukkit 1.13 or newer. Some features are only available in newer releases. Make sure to use the latest release of your server software before reporting issues. diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..e828ba4 Binary files /dev/null and b/icon.png differ diff --git a/screenshot.png b/screenshot.png new file mode 100644 index 0000000..3bd632a Binary files /dev/null and b/screenshot.png differ diff --git a/src/main/java/net/craftcitizen/imagemaps/ImageMap.java b/src/main/java/net/craftcitizen/imagemaps/ImageMap.java index 14286c4..dff5266 100644 --- a/src/main/java/net/craftcitizen/imagemaps/ImageMap.java +++ b/src/main/java/net/craftcitizen/imagemaps/ImageMap.java @@ -4,7 +4,9 @@ import java.util.HashMap; import java.util.Map; import org.bukkit.configuration.serialization.ConfigurationSerializable; +import org.bukkit.configuration.serialization.SerializableAs; +@SerializableAs("ImageMaps.Map") public class ImageMap implements ConfigurationSerializable { private String filename; diff --git a/src/main/java/net/craftcitizen/imagemaps/ImageMapListCommand.java b/src/main/java/net/craftcitizen/imagemaps/ImageMapListCommand.java index e784a3d..04e48a3 100644 --- a/src/main/java/net/craftcitizen/imagemaps/ImageMapListCommand.java +++ b/src/main/java/net/craftcitizen/imagemaps/ImageMapListCommand.java @@ -11,6 +11,7 @@ import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; +import net.md_5.bungee.api.chat.ClickEvent.Action; public class ImageMapListCommand extends ImageMapSubCommand { @@ -24,18 +25,16 @@ public class ImageMapListCommand extends ImageMapSubCommand { MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.WARNING, "You can't run this command."); return null; } - - long page = args.length >= 2 ? Utils.parseIntegerOrDefault(args[1], 0) - 1 : 0; - + String[] fileList = new File(plugin.getDataFolder(), "images").list(); + long page = args.length >= 2 ? Utils.parseIntegerOrDefault(args[1], 0) - 1 : 0; + int numPages = (int) Math.ceil((double) fileList.length / Utils.ELEMENTS_PER_PAGE); - MessageUtil.sendMessage(plugin, - sender, - MessageLevel.INFO, - String.format("Image List %d/%d", page + 1, (int) Math.ceil((double) fileList.length / Utils.ELEMENTS_PER_PAGE))); - // TODO alternating color - Utils.paginate(fileList, page).forEach(filename -> { + MessageUtil.sendMessage(plugin, sender, MessageLevel.INFO, String.format("## Image List Page %d of %d ##", page + 1, numPages)); + + boolean even = false; + for(String filename : Utils.paginate(fileList, page)) { BaseComponent infoAction = new TextComponent("[Info]"); infoAction.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/imagemap info " + filename)); infoAction.setColor(ChatColor.GOLD); @@ -47,6 +46,7 @@ public class ImageMapListCommand extends ImageMapSubCommand { placeAction.setColor(ChatColor.GOLD); BaseComponent message = new TextComponent(filename); + message.setColor(even ? ChatColor.GRAY : ChatColor.WHITE); message.addExtra(" "); message.addExtra(infoAction); message.addExtra(" "); @@ -55,7 +55,19 @@ public class ImageMapListCommand extends ImageMapSubCommand { message.addExtra(placeAction); MessageUtil.sendMessage(plugin, sender, MessageLevel.NORMAL, message); - }); + even = !even; + } + + BaseComponent navigation = new TextComponent(); + BaseComponent prevPage = new TextComponent(String.format("<< Page %d", Math.max(page, 1))); + BaseComponent nextPage = new TextComponent(String.format("Page %d >>", Math.min(page + 1, numPages))); + prevPage.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/imagemap list " + Math.max(page, 1))); + nextPage.setClickEvent(new ClickEvent(Action.RUN_COMMAND, "/imagemap list " + Math.min(page + 2, numPages))); + + navigation.addExtra(prevPage); + navigation.addExtra(" | "); + navigation.addExtra(nextPage); + MessageUtil.sendMessage(plugin, sender, MessageLevel.INFO, navigation); return null; } diff --git a/src/main/java/net/craftcitizen/imagemaps/ImageMapPlaceCommand.java b/src/main/java/net/craftcitizen/imagemaps/ImageMapPlaceCommand.java index 356579c..41cca6f 100644 --- a/src/main/java/net/craftcitizen/imagemaps/ImageMapPlaceCommand.java +++ b/src/main/java/net/craftcitizen/imagemaps/ImageMapPlaceCommand.java @@ -15,9 +15,6 @@ import de.craftlancer.core.util.MessageLevel; import de.craftlancer.core.util.MessageUtil; import de.craftlancer.core.util.Tuple; -/* - * imagemap place - */ public class ImageMapPlaceCommand extends ImageMapSubCommand { public ImageMapPlaceCommand(ImageMaps plugin) { diff --git a/src/main/java/net/craftcitizen/imagemaps/ImageMapReloadCommand.java b/src/main/java/net/craftcitizen/imagemaps/ImageMapReloadCommand.java index 1594f3b..6b6de91 100644 --- a/src/main/java/net/craftcitizen/imagemaps/ImageMapReloadCommand.java +++ b/src/main/java/net/craftcitizen/imagemaps/ImageMapReloadCommand.java @@ -40,7 +40,7 @@ public class ImageMapReloadCommand extends ImageMapSubCommand { MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.NORMAL, "Image reloaded."); else MessageUtil.sendMessage(getPlugin(), sender, MessageLevel.NORMAL, "Image couldn't be reloaded (does it exist?)."); - + return null; } diff --git a/src/main/java/net/craftcitizen/imagemaps/ImageMaps.java b/src/main/java/net/craftcitizen/imagemaps/ImageMaps.java index fddc39a..5dfa114 100644 --- a/src/main/java/net/craftcitizen/imagemaps/ImageMaps.java +++ b/src/main/java/net/craftcitizen/imagemaps/ImageMaps.java @@ -50,6 +50,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.TextComponent; public class ImageMaps extends JavaPlugin implements Listener { + private static final String MAPS_YML = "maps.yml"; private static final String CONFIG_VERSION_KEY = "storageVersion"; private static final int CONFIG_VERSION = 1; private static final long AUTOSAVE_PERIOD = 18000L; // 15 minutes @@ -137,7 +138,7 @@ public class ImageMaps extends JavaPlugin implements Listener { BukkitRunnable saveTask = new LambdaRunnable(() -> { try { - config.save(new File(getDataFolder(), "maps.yml")); + config.save(new File(getDataFolder(), MAPS_YML)); } catch (IOException e) { e.printStackTrace(); @@ -151,7 +152,7 @@ public class ImageMaps extends JavaPlugin implements Listener { } private void loadMaps() { - Configuration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "maps.yml")); + Configuration config = YamlConfiguration.loadConfiguration(new File(getDataFolder(), MAPS_YML)); int version = config.getInt(CONFIG_VERSION_KEY, -1); if (version == -1) @@ -167,7 +168,11 @@ public class ImageMaps extends JavaPlugin implements Listener { BufferedImage image = getImage(imageMap.getFilename()); if (image == null) { - getLogger().warning(() -> "Image file " + image + " not found. Removing map!"); + getLogger().warning(() -> "Image file " + imageMap.getFilename() + " not found. Removing map!"); + return; + } + if (map == null) { + getLogger().warning(() -> "Map " + id + " referenced but does not exist. Removing map!"); return; } @@ -180,7 +185,7 @@ public class ImageMaps extends JavaPlugin implements Listener { getLogger().info("Converting maps from Version <1.0"); try { - Files.copy(new File(getDataFolder(), "maps.yml"), new File(getDataFolder(), "maps.yml.backup")); + Files.copy(new File(getDataFolder(), MAPS_YML), new File(getDataFolder(), MAPS_YML + ".backup")); } catch (IOException e) { getLogger().severe("Failed to backup maps.yml!");