Implemented the statistic books of the list GUI in the new architecture.

* NEW: added statistics to the new list GUI.
This commit is contained in:
Amaury Carrade 2015-09-10 15:27:09 +02:00
parent 1ddc923b73
commit e7acbb36c4
2 changed files with 87 additions and 5 deletions

View File

@ -18,10 +18,11 @@
package fr.moribus.imageonmap.guiproko.list;
import fr.moribus.imageonmap.guiproko.core.ExplorerGui;
import fr.moribus.imageonmap.map.PosterMap;
import fr.moribus.imageonmap.ui.MapItemManager;
import org.bukkit.inventory.ItemStack;
import fr.moribus.imageonmap.guiproko.core.*;
import fr.moribus.imageonmap.map.*;
import fr.moribus.imageonmap.ui.*;
import org.bukkit.inventory.*;
public class MapDetailGui extends ExplorerGui<Void>
{
@ -43,5 +44,4 @@ public class MapDetailGui extends ExplorerGui<Void>
setTitle("Details for map " + map.getName());
setDataShape(map.getColumnCount(), map.getRowCount());
}
}

View File

@ -18,14 +18,22 @@
package fr.moribus.imageonmap.guiproko.list;
import fr.moribus.imageonmap.*;
import fr.moribus.imageonmap.guiproko.core.*;
import fr.moribus.imageonmap.map.*;
import fr.moribus.imageonmap.ui.*;
import org.bukkit.*;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.*;
import java.text.*;
import java.util.*;
public class MapListGui extends ExplorerGui<ImageMap>
{
private final NumberFormat bigNumbersFormatter = new DecimalFormat("###,###,###,###", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
@Override
protected ItemStack getViewItem(ImageMap data)
@ -66,5 +74,79 @@ public class MapListGui extends ExplorerGui<ImageMap>
setTitle("Your maps (" + maps.length + " total)");
setKeepHorizontalScrollingSpace(true);
/* ** Statistics ** */
int imagesCount = MapManager.getMapList(getPlayer().getUniqueId()).size();
int mapPartCount = MapManager.getMapPartCount(getPlayer().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);
}
fr.moribus.imageonmap.gui.core.GuiUtils.removeVanillaInfos(meta);
statistics.setItemMeta(meta);
action("", getSize() - 5, statistics);
}
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;
}
}