Added proper support for older posters without dimensions.

* NEW: MapDetailGui: Use regular items to represent Single maps, so the
  user can retrieve them.
* NEW: MapDetailGui: Added support for posters without dimensions.
* NEW: MapListGui: Added support for posters without dimensions.
* NEW: MapItemManager: Added support for posters without dimensions.
* BUG: SplatterMapManager: Prevent the use of splatter maps with posters
  without dimensions.
* BUG: PlayerMapStore: Fix the console warning when loading a map store
  that exceeds the quotas.
* BUG: Minor fixes to the french translation.
This commit is contained in:
Adrien Prokopowicz 2016-07-07 02:04:13 +02:00
parent a90418d3a1
commit db8d1d9551
6 changed files with 99 additions and 21 deletions

View File

@ -29,11 +29,12 @@ import fr.zcraft.zlib.components.gui.PromptGui;
import fr.zcraft.zlib.components.i18n.I; import fr.zcraft.zlib.components.i18n.I;
import fr.zcraft.zlib.tools.Callback; import fr.zcraft.zlib.tools.Callback;
import fr.zcraft.zlib.tools.items.ItemStackBuilder; import fr.zcraft.zlib.tools.items.ItemStackBuilder;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class MapDetailGui extends ExplorerGui public class MapDetailGui extends ExplorerGui<Short>
{ {
private final ImageMap map; private final ImageMap map;
@ -58,6 +59,22 @@ public class MapDetailGui extends ExplorerGui
.item(); .item();
} }
@Override
protected ItemStack getViewItem(Short mapId)
{
int index = ((PosterMap) map).getIndex(mapId);
Material partMaterial = Material.PAPER;
if(index % 2 == 0)
partMaterial = Material.EMPTY_MAP;
return new ItemStackBuilder(partMaterial)
.title(I.t("{green}Map part"))
.lore(I.t("{gray}Part: {white}{0}", index + 1))
.loreLine()
.lore(I.t("{gray}» {white}Click{gray} to get only this part"))
.item();
}
@Override @Override
protected ItemStack getPickedUpItem(int x, int y) protected ItemStack getPickedUpItem(int x, int y)
{ {
@ -73,6 +90,13 @@ public class MapDetailGui extends ExplorerGui
throw new IllegalStateException("Unsupported map type: " + map.getType()); throw new IllegalStateException("Unsupported map type: " + map.getType());
} }
@Override
protected ItemStack getPickedUpItem(Short mapId)
{
PosterMap poster = (PosterMap) map;
return MapItemManager.createMapItem(poster, poster.getIndex(mapId));
}
@Override @Override
protected ItemStack getEmptyViewItem() protected ItemStack getEmptyViewItem()
{ {
@ -91,9 +115,21 @@ public class MapDetailGui extends ExplorerGui
setKeepHorizontalScrollingSpace(true); setKeepHorizontalScrollingSpace(true);
if(map instanceof PosterMap) if(map instanceof PosterMap)
setDataShape(((PosterMap) map).getColumnCount(), ((PosterMap) map).getRowCount()); {
PosterMap poster = (PosterMap) map;
if(poster.hasColumnData())
{
setDataShape(poster.getColumnCount(), poster.getRowCount());
}
else
{
setData(ArrayUtils.toObject(poster.getMapsIDs()));
}
}
else else
setData(null); // Fallback to the empty view item. {
setDataShape(1,1);
}
action("rename", getSize() - 7, new ItemStackBuilder(Material.BOOK_AND_QUILL) action("rename", getSize() - 7, new ItemStackBuilder(Material.BOOK_AND_QUILL)

View File

@ -39,12 +39,24 @@ public class MapListGui extends ExplorerGui<ImageMap>
{ {
String mapDescription; String mapDescription;
if (map instanceof SingleMap) if (map instanceof SingleMap)
{
/// Displayed subtitle description of a single map on the list GUI /// Displayed subtitle description of a single map on the list GUI
mapDescription = I.t("{white}Single map"); mapDescription = I.t("{white}Single map");
}
else else
/// Displayed subtitle description of a poster map on the list GUI (columns × rows in english) {
mapDescription = I.t("{white}Poster map ({0} × {1})", ((PosterMap) map).getColumnCount(), ((PosterMap) map).getRowCount()); PosterMap poster = (PosterMap) map;
if(poster.hasColumnData())
{
/// Displayed subtitle description of a poster map on the list GUI (columns × rows in english)
mapDescription = I.t("{white}Poster map ({0} × {1})", poster.getColumnCount(), poster.getRowCount());
}
else
{
/// Displayed subtitle description of a poster map without column data on the list GUI
mapDescription = I.t("{white}Poster map ({0} parts)", poster.getMapCount());
}
}
return new ItemStackBuilder(Material.MAP) return new ItemStackBuilder(Material.MAP)
/// Displayed title of a map on the list GUI /// Displayed title of a map on the list GUI
.title(I.t("{green}{bold}{0}", map.getName())) .title(I.t("{green}{bold}{0}", map.getName()))
@ -84,7 +96,13 @@ public class MapListGui extends ExplorerGui<ImageMap>
} }
else if (map instanceof PosterMap) else if (map instanceof PosterMap)
{ {
return SplatterMapManager.makeSplatterMap((PosterMap) map); PosterMap poster = (PosterMap) map;
if(poster.hasColumnData())
return SplatterMapManager.makeSplatterMap((PosterMap) map);
MapItemManager.giveParts(getPlayer(), poster);
return null;
} }
MapItemManager.give(getPlayer(), map); MapItemManager.give(getPlayer(), map);

View File

@ -223,7 +223,7 @@ public class PlayerMapStore implements ConfigurationSerializable
try { checkMapLimit(0); } try { checkMapLimit(0); }
catch(MapManagerException ex) catch(MapManagerException ex)
{ {
PluginLogger.warning("Map limit exceeded for player '{0}' ({1} maps loaded)", PluginLogger.warning("Map limit exceeded for player {0} ({1} maps loaded)",
playerUUID.toString(),mapList.size()); playerUUID.toString(),mapList.size());
} }
} }

View File

@ -73,9 +73,32 @@ public class MapItemManager implements Listener
static public boolean give(Player player, PosterMap map) static public boolean give(Player player, PosterMap map)
{ {
if(!map.hasColumnData())
return giveParts(player, map);
return give(player, SplatterMapManager.makeSplatterMap(map)); return give(player, SplatterMapManager.makeSplatterMap(map));
} }
static public boolean giveParts(Player player, PosterMap map)
{
boolean inventoryFull = false;
ItemStack mapPartItem;
for(int i = 0, c = map.getMapCount(); i < c; i++)
{
if(map.hasColumnData())
{
mapPartItem = createMapItem(map, map.getRowAt(i), map.getColumnAt(i));
}
else
{
mapPartItem = createMapItem(map, i);
}
inventoryFull = give(player, mapPartItem) || inventoryFull;
}
return inventoryFull;
}
static public int giveCache(Player player) static public int giveCache(Player player)
{ {
Queue<ItemStack> cache = getCache(player); Queue<ItemStack> cache = getCache(player);
@ -110,19 +133,16 @@ public class MapItemManager implements Listener
return createMapItem(map.getMapsIDs()[0], map.getName()); return createMapItem(map.getMapsIDs()[0], map.getName());
} }
static public ItemStack createMapItem(PosterMap map, int index)
{
/// The name of a map item given to a player, if splatter maps are not used. 0 = map name; 1 = index.
return createMapItem(map.getMapIdAt(index), I.t("{0} (part {1})", map.getName(), index + 1));
}
static public ItemStack createMapItem(PosterMap map, int x, int y) static public ItemStack createMapItem(PosterMap map, int x, int y)
{ {
String mapName; /// The name of a map item given to a player, if splatter maps are not used. 0 = map name; 1 = row; 2 = column.
if(map.hasColumnData()) return createMapItem(map.getMapIdAt(x, y), I.t("{0} (row {1}, column {2})", map.getName(), x + 1, y + 1));
{
/// The name of a map item given to a player, if splatter maps are not used. 0 = map name; 1 = row; 2 = column.
mapName = I.t("{0} (row {1}, column {2})", map.getName(), x, y);
}
else
{
mapName = map.getName();
}
return createMapItem(map.getMapIdAt(x, y), mapName);
} }
static public ItemStack createMapItem(short mapID, String text) static public ItemStack createMapItem(short mapID, String text)
@ -192,7 +212,10 @@ public class MapItemManager implements Listener
{ {
PosterMap poster = (PosterMap) map; PosterMap poster = (PosterMap) map;
int index = poster.getIndex(item.getDurability()); int index = poster.getIndex(item.getDurability());
return I.t("{0} (row {1}, column {2})", map.getName(), poster.getRowAt(index), poster.getColumnAt(index)); if(poster.hasColumnData())
return I.t("{0} (row {1}, column {2})", map.getName(), poster.getRowAt(index) + 1, poster.getColumnAt(index) + 1);
return I.t("{0} (part {1})", map.getName(), index + 1);
} }
} }

View File

@ -117,6 +117,7 @@ abstract public class SplatterMapManager
ImageMap map = MapManager.getMap(startFrame.getItem()); ImageMap map = MapManager.getMap(startFrame.getItem());
if(map == null || !(map instanceof PosterMap)) return null; if(map == null || !(map instanceof PosterMap)) return null;
PosterMap poster = (PosterMap) map; PosterMap poster = (PosterMap) map;
if(!poster.hasColumnData()) return null;
FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing()); FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
ItemFrame[] matchingFrames = PosterWall.getMatchingMapFrames(poster, loc, startFrame.getItem().getDurability()); ItemFrame[] matchingFrames = PosterWall.getMatchingMapFrames(poster, loc, startFrame.getItem().getDurability());
if(matchingFrames == null) return null; if(matchingFrames == null) return null;

View File

@ -237,7 +237,7 @@ msgstr "{gray}Identifiant : {white}{0}"
#: src/main/java/fr/moribus/imageonmap/gui/MapListGui.java:57 #: src/main/java/fr/moribus/imageonmap/gui/MapListGui.java:57
msgid "{gray}» {white}Left-click{gray} to get this map" msgid "{gray}» {white}Left-click{gray} to get this map"
msgstr "{gray}» {white}Cliquez droit{gray} pour récupérer cette carte" msgstr "{gray}» {white}Cliquez gauche{gray} pour récupérer cette carte"
#: src/main/java/fr/moribus/imageonmap/gui/MapListGui.java:58 #: src/main/java/fr/moribus/imageonmap/gui/MapListGui.java:58
msgid "{gray}» {white}Right-click{gray} for details and options" msgid "{gray}» {white}Right-click{gray} for details and options"