Added some statistics on the maps list GUI.

* NEW: Added a book displaying statistics on the maps list GUI, with images rendered, Minecraft maps used, and Minecraft-maps-limits-related statistics if these limits exists.
This commit is contained in:
Amaury Carrade 2015-07-14 03:13:49 +02:00
parent a3195327ac
commit 4f3e856a73
2 changed files with 99 additions and 1 deletions

View File

@ -18,6 +18,7 @@
package fr.moribus.imageonmap.gui.list;
import fr.moribus.imageonmap.*;
import fr.moribus.imageonmap.gui.core.*;
import fr.moribus.imageonmap.map.*;
import fr.moribus.imageonmap.ui.MapItemManager;
@ -27,6 +28,7 @@ import org.bukkit.event.inventory.*;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.*;
import java.text.*;
import java.util.*;
@ -34,6 +36,8 @@ public class MapListGui extends AbstractGui
{
private final Integer MAPS_PER_PAGE = 7 * 3;
private final NumberFormat bigNumbersFormatter = new DecimalFormat("###,###,###,###", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
private List<ImageMap> maps = new ArrayList<>();
@ -56,6 +60,68 @@ public class MapListGui extends AbstractGui
player.openInventory(getInventory());
/* ** Statistics ** */
int imagesCount = MapManager.getMapList(player.getUniqueId()).size();
int mapPartCount = MapManager.getMapPartCount(player.getUniqueId());
int mapGlobalLimit = PluginConfiguration.MAP_GLOBAL_LIMIT.getInteger();
int mapPersonalLimit = PluginConfiguration.MAP_PLAYER_LIMIT.getInteger();
int mapPartGloballyLeft = mapGlobalLimit - MapManager.getMapCount();
int mapPartPersonallyLeft = mapPersonalLimit - mapPartCount;
int mapPartLeft;
if(mapGlobalLimit <= 0 && mapPersonalLimit <= 0)
mapPartLeft = -1;
else if(mapGlobalLimit <= 0)
mapPartLeft = mapPartPersonallyLeft;
else if(mapPersonalLimit <= 0)
mapPartLeft = mapPartGloballyLeft;
else
mapPartLeft = Math.min(mapPartGloballyLeft, mapPartPersonallyLeft);
double percentageUsed = mapPartLeft < 0 ? 0 : ((double) mapPartCount) / ((double) (mapPartCount + mapPartLeft)) * 100;
ItemStack statistics = new ItemStack(Material.ENCHANTED_BOOK);
ItemMeta meta = statistics.getItemMeta();
meta.setDisplayName(ChatColor.BLUE + "Usage statistics");
meta.setLore(Arrays.asList(
"",
getStatisticText("Images rendered", imagesCount),
getStatisticText("Minecraft maps used", mapPartCount)
));
if(mapPartLeft >= 0)
{
List<String> lore = meta.getLore();
lore.add("");
lore.add(ChatColor.BLUE + "Minecraft maps limits");
lore.add("");
lore.add(getStatisticText("Server-wide limit", mapGlobalLimit, true));
lore.add(getStatisticText("Per-player limit", mapPersonalLimit, true));
lore.add("");
lore.add(getStatisticText("Current consumption", ((int) Math.rint(percentageUsed)) + " %"));
lore.add(getStatisticText("Maps left", mapPartLeft));
lore.add("");
meta.setLore(lore);
}
GuiUtils.removeVanillaInfos(meta);
statistics.setItemMeta(meta);
setSlotData(statistics, inventory.getSize() - 5, "");
/* ** Maps ** */
update(player);
}
@ -270,4 +336,19 @@ public class MapListGui extends AbstractGui
return icon;
}
private String getStatisticText(String title, Integer value)
{
return getStatisticText(title, value, false);
}
private String getStatisticText(String title, Integer value, boolean zeroIsUnlimited)
{
return getStatisticText(title, zeroIsUnlimited && value <= 0 ? "unlimited" : bigNumbersFormatter.format(value));
}
private String getStatisticText(String title, String value)
{
return ChatColor.GRAY + title + ": " + ChatColor.WHITE + value;
}
}

View File

@ -138,6 +138,18 @@ abstract public class MapManager
{
return getPlayerMapStore(playerUUID).getMapList();
}
/**
* Returns the number of minecraft maps used by the images rendered by the given player.
*
* @param playerUUID The player's UUID.
*
* @return The count.
*/
static public int getMapPartCount(UUID playerUUID)
{
return getPlayerMapStore(playerUUID).getMapCount();
}
static public ImageMap getMap(UUID playerUUID, String mapId)
{
@ -231,7 +243,12 @@ abstract public class MapManager
}
getPlayerMapStore(userUUID).checkMapLimit(newMapsCount);
}
/**
* Returns the total number of minecraft maps used by ImageOnMap images.
*
* @return The count.
*/
static public int getMapCount()
{
int mapCount = 0;