mirror of
https://github.com/SydMontague/ImageMaps.git
synced 2024-11-25 03:45:13 +01:00
Improve list UX, filter invalid maps
This commit is contained in:
parent
d9ff43a78a
commit
a15f79e287
@ -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.
|
||||
|
BIN
screenshot.png
Normal file
BIN
screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 751 KiB |
@ -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;
|
||||
|
@ -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 {
|
||||
|
||||
@ -25,17 +26,15 @@ public class ImageMapListCommand extends ImageMapSubCommand {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,6 @@ import de.craftlancer.core.util.MessageLevel;
|
||||
import de.craftlancer.core.util.MessageUtil;
|
||||
import de.craftlancer.core.util.Tuple;
|
||||
|
||||
/*
|
||||
* imagemap place <image> <scale> <isVisible> <isFixed>
|
||||
*/
|
||||
public class ImageMapPlaceCommand extends ImageMapSubCommand {
|
||||
|
||||
public ImageMapPlaceCommand(ImageMaps plugin) {
|
||||
|
@ -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!");
|
||||
|
Loading…
Reference in New Issue
Block a user