mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-01-20 22:41:20 +01:00
* NEW: Poster map items now show position information.
This commit is contained in:
parent
ca8cebd0a0
commit
2280e96125
@ -18,6 +18,7 @@
|
||||
|
||||
package fr.moribus.imageonmap.map;
|
||||
|
||||
import fr.moribus.imageonmap.ui.MapItemManager;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@ -75,12 +76,7 @@ public abstract class ImageMap implements ConfigurationSerializable
|
||||
|
||||
public void give(Inventory inventory)
|
||||
{
|
||||
short[] mapsIDs = getMapsIDs();
|
||||
for(short mapID : mapsIDs)
|
||||
{
|
||||
ItemStack itemMap = new ItemStack(Material.MAP, 1, mapID);
|
||||
inventory.addItem(itemMap);
|
||||
}
|
||||
MapItemManager.give(inventory, this);
|
||||
}
|
||||
|
||||
/* ====== Serialization methods ====== */
|
||||
|
@ -78,5 +78,27 @@ public class PosterMap extends ImageMap
|
||||
map.put("rows", rowCount);
|
||||
map.put("mapsIDs", mapsIDs);
|
||||
}
|
||||
|
||||
/* ====== Getters & Setters ====== */
|
||||
|
||||
public int getColumnCount()
|
||||
{
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
public int getRowCount()
|
||||
{
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public int getColumnAt(int i)
|
||||
{
|
||||
return (i % columnCount) + 1;
|
||||
}
|
||||
|
||||
public int getRowAt(int i)
|
||||
{
|
||||
return (i / columnCount) + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
64
src/main/java/fr/moribus/imageonmap/ui/MapItemManager.java
Normal file
64
src/main/java/fr/moribus/imageonmap/ui/MapItemManager.java
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Moribus
|
||||
* Copyright (C) 2015 ProkopyL <prokopylmc@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package fr.moribus.imageonmap.ui;
|
||||
|
||||
import fr.moribus.imageonmap.map.ImageMap;
|
||||
import fr.moribus.imageonmap.map.PosterMap;
|
||||
import fr.moribus.imageonmap.map.SingleMap;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class MapItemManager implements Listener
|
||||
{
|
||||
static public void give(Inventory inventory, ImageMap map)
|
||||
{
|
||||
if(map instanceof PosterMap) give(inventory, (PosterMap) map);
|
||||
else if(map instanceof SingleMap) give(inventory, (SingleMap) map);
|
||||
}
|
||||
|
||||
static public void give(Inventory inventory, SingleMap map)
|
||||
{
|
||||
inventory.addItem(createMapItem(map.getMapsIDs()[0], map.getName()));
|
||||
}
|
||||
|
||||
static public void give(Inventory inventory, PosterMap map)
|
||||
{
|
||||
short[] mapsIDs = map.getMapsIDs();
|
||||
for(int i = 0, c = mapsIDs.length; i < c; i++)
|
||||
{
|
||||
inventory.addItem(createMapItem(mapsIDs[i], map.getName() +
|
||||
" (row " + map.getRowAt(i) +
|
||||
", column " + map.getColumnAt(i) + ")"));
|
||||
}
|
||||
}
|
||||
|
||||
static public ItemStack createMapItem(short mapID, String text)
|
||||
{
|
||||
ItemStack itemMap = new ItemStack(Material.MAP, 1, mapID);
|
||||
|
||||
ItemMeta meta = itemMap.getItemMeta();
|
||||
meta.setDisplayName(text);
|
||||
itemMap.setItemMeta(meta);
|
||||
|
||||
return itemMap;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user