use of com.elmakers.mine.bukkit.api.maps.URLMap in project MagicPlugin by elBukkit.
the class MagicMapCommandExecutor method onMapRestore.
protected void onMapRestore(CommandSender sender, World world, int mapId) {
final boolean backwards = mapId > 1;
String direction = ChatColor.YELLOW + " " + (backwards ? "moving backward" : "moving forward");
sender.sendMessage(ChatColor.AQUA + "Restoring maps, starting at id " + ChatColor.DARK_AQUA + mapId + direction);
// Getting dirty now!
MapController apiController = api.getController().getMaps();
com.elmakers.mine.bukkit.maps.MapController mapController = (com.elmakers.mine.bukkit.maps.MapController) apiController;
List<URLMap> maps = mapController.getAll();
Set<String> urls = new HashSet<>();
Set<Integer> ids = new HashSet<>();
int maxId = 0;
final String skinURL = "http://skins.minecraft.net/MinecraftSkins/";
final String alternateSkinURL = "http://s3.amazonaws.com/MinecraftSkins/";
for (URLMap map : maps) {
maxId = Math.max(maxId, map.getId());
if (map.getURL().startsWith(skinURL) && map.getName() == null) {
map.setName("Photo of " + map.getURL().replace(skinURL, "").replace(".png", ""));
sender.sendMessage("Added name to " + map.getName());
} else if (map.getURL().startsWith(alternateSkinURL) && map.getName() == null) {
map.setName("Photo of " + map.getURL().replace(alternateSkinURL, "").replace(".png", ""));
sender.sendMessage("Added name to " + map.getName());
}
urls.add(map.getURL());
ids.add((int) map.getId());
}
if (!backwards) {
mapId = maxId;
}
int addedFiles = 0;
File[] cacheFiles = mapController.getCacheFolder().listFiles();
Arrays.sort(cacheFiles, new Comparator<File>() {
@Override
public int compare(File f1, File f2) {
if (backwards) {
return Long.compare(f2.lastModified(), f1.lastModified());
}
return Long.compare(f1.lastModified(), f2.lastModified());
}
});
for (File cacheFile : cacheFiles) {
try {
while (mapId > 0 && ids.contains(mapId)) mapId--;
if (mapId <= 0)
break;
if (cacheFile.getName().startsWith(".") || cacheFile.isDirectory())
continue;
String url = URLDecoder.decode(cacheFile.getName(), "UTF-8");
if (urls.contains(url)) {
sender.sendMessage("Skipping " + url);
continue;
}
String name = null;
int x = 0;
int y = 0;
int width = 0;
int height = 0;
Integer xOverlay = null;
Integer yOverlay = null;
if (url.startsWith(skinURL) || url.startsWith(alternateSkinURL)) {
name = "Photo of " + url.replace(skinURL, "").replace(alternateSkinURL, "").replace(".png", "");
x = 8;
y = 8;
width = 8;
height = 8;
xOverlay = 40;
yOverlay = 8;
sender.sendMessage("Added " + mapId + " as player skin: " + name);
} else {
sender.sendMessage("Added " + mapId + " as: " + url);
}
mapController.get(world.getName(), (short) mapId, url, name, x, y, xOverlay, yOverlay, width, height, null);
addedFiles++;
if (backwards) {
mapId--;
} else {
mapId++;
}
} catch (UnsupportedEncodingException ex) {
sender.sendMessage("Error decoding: " + cacheFile.getName());
}
}
mapController.save();
sender.sendMessage(ChatColor.AQUA + "Restored " + ChatColor.DARK_AQUA + addedFiles);
}
use of com.elmakers.mine.bukkit.api.maps.URLMap in project MagicPlugin by elBukkit.
the class MagicMapCommandExecutor method onMapName.
protected void onMapName(CommandSender sender, String mapName) {
if (!(sender instanceof Player)) {
sender.sendMessage("This command only works in-game");
return;
}
Player player = (Player) sender;
ItemStack currentMap = player.getInventory().getItemInMainHand();
if (currentMap == null || currentMap.getType() != Material.MAP) {
sender.sendMessage("You must be holding a map");
return;
}
MapController mapController = api.getController().getMaps();
URLMap map = mapController.getMap(currentMap.getDurability());
if (map == null) {
sender.sendMessage("Map id " + currentMap.getDurability() + " is not registered");
return;
}
map.setName(mapName);
mapController.save();
sender.sendMessage("Renamed map id " + map.getId() + " to " + map.getName());
player.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
}
use of com.elmakers.mine.bukkit.api.maps.URLMap in project MagicPlugin by elBukkit.
the class MagicMapCommandExecutor method onMapFix.
protected void onMapFix(CommandSender sender, World world, int retries) {
sender.sendMessage(ChatColor.AQUA + "Fixing maps, using up to " + ChatColor.DARK_AQUA + retries + ChatColor.AQUA + " ids at a time.");
MapController mapController = api.getController().getMaps();
List<URLMap> maps = mapController.getAll();
int fixed = 0;
int notFixed = 0;
int skipped = 0;
for (URLMap map : maps) {
if (map.isEnabled()) {
skipped++;
} else {
if (map.fix(world, retries)) {
fixed++;
} else {
notFixed++;
}
}
}
mapController.save();
sender.sendMessage(ChatColor.AQUA + "Fixed " + ChatColor.DARK_AQUA + fixed + ChatColor.AQUA + " and skipped " + ChatColor.DARK_AQUA + skipped + ChatColor.AQUA + " maps");
if (notFixed > 0) {
sender.sendMessage(ChatColor.RED + "There are still " + ChatColor.DARK_RED + notFixed + ChatColor.RED + " maps disabled, you may want to try running this command again.");
}
}
use of com.elmakers.mine.bukkit.api.maps.URLMap in project MagicPlugin by elBukkit.
the class MagicMapCommandExecutor method onMapUnnamed.
protected void onMapUnnamed(CommandSender sender) {
if (!(sender instanceof Player)) {
sender.sendMessage("This command only works in-game");
return;
}
Player player = (Player) sender;
MapController mapController = api.getController().getMaps();
List<URLMap> maps = mapController.getAll();
for (URLMap map : maps) {
if (map.getName() == null) {
ItemStack newMap = new ItemStack(Material.MAP, 1);
newMap.setDurability(map.getId());
api.giveItemToPlayer(player, newMap);
sender.sendMessage("Found unnamed map id " + map.getId() + " with url " + ChatColor.AQUA + map.getURL());
return;
}
}
sender.sendMessage("There are no unnamed maps!");
}
use of com.elmakers.mine.bukkit.api.maps.URLMap in project MagicPlugin by elBukkit.
the class MagicMapExecutor method onMapList.
protected void onMapList(CommandSender sender, String keyword) {
Pattern pattern = null;
boolean positive = true;
if (!keyword.isEmpty()) {
if (keyword.startsWith("-")) {
keyword = keyword.substring(1);
positive = false;
}
pattern = Pattern.compile(keyword);
}
int shown = 0;
boolean limited = false;
List<URLMap> maps = api.getController().getMaps().getAll();
Collections.reverse(maps);
for (URLMap map : maps) {
short mapId = map.getId();
String source = map.getName() + " " + map.getURL() + " " + map.getId();
Matcher matcher = pattern == null ? null : pattern.matcher(source);
if (matcher == null || matcher.find() == positive) {
shown++;
String name = map.getName();
name = (name == null ? "(None)" : name);
sender.sendMessage(ChatColor.AQUA + "" + mapId + ChatColor.WHITE + ": " + name + " => " + ChatColor.GRAY + map.getURL());
if (shown > 100) {
limited = true;
break;
}
}
}
if (shown == 0) {
sender.sendMessage("No maps found" + (keyword.length() > 0 ? " matching " + keyword : "") + ", use /mmap load to add more maps");
} else if (keyword.isEmpty()) {
if (limited) {
sender.sendMessage("Results limited to 100, use /mmap list <keyword> to narrow your search");
} else {
sender.sendMessage(shown + " maps found");
}
} else {
String limitedMessage = limited ? " (+ more)" : "";
sender.sendMessage(shown + " maps found matching " + keyword + limitedMessage);
}
}
Aggregations