mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2024-09-24 20:53:07 +02:00
Fix Splatter map deployment.
* NEW: Incomplete splatter maps can now be retreived by shift-clicking. * NEW: When in creative mode, retreived maps are given back when not in the player's inventory. * BUG: Splatter maps are now deployed correctly.
This commit is contained in:
parent
3bfa1266ad
commit
c18202f800
@ -114,11 +114,6 @@ public class PosterImage
|
||||
return cutImages[i];
|
||||
}
|
||||
|
||||
public BufferedImage getImageAt(int x, int y)
|
||||
{
|
||||
return cutImages[x * columns + y];
|
||||
}
|
||||
|
||||
public int getColumnAt(int i)
|
||||
{
|
||||
return i % columns;
|
||||
|
@ -125,23 +125,23 @@ public class PosterMap extends ImageMap
|
||||
/**
|
||||
* Returns the map id at the given column and line.
|
||||
*
|
||||
* @param col The column. Starts at 0.
|
||||
* @param row The row. Starts at 0.
|
||||
* @param x The x coordinate. Starts at 0.
|
||||
* @param y The y coordinate. Starts at 0.
|
||||
* @return The Minecraft map ID.
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException if the given coordinates are too big (out of the poster).
|
||||
*/
|
||||
public short getMapIdAt(int col, int row)
|
||||
public short getMapIdAt(int x, int y)
|
||||
{
|
||||
return mapsIDs[getColumnCount() * row + col];
|
||||
return mapsIDs[y * columnCount + x];
|
||||
}
|
||||
|
||||
public short getMapIdAtReverseY(int index)
|
||||
{
|
||||
int col = index % (columnCount);
|
||||
int row = index / (rowCount - 1);
|
||||
System.out.println(col + " : " + row + " (" + index);
|
||||
return getMapIdAt(col, rowCount - row - 1);
|
||||
int x = index % (columnCount);
|
||||
int y = index / (columnCount);
|
||||
System.out.println(x + " : " + (rowCount - y - 1) + " (" + index);
|
||||
return getMapIdAt(x, rowCount - y - 1);
|
||||
}
|
||||
|
||||
public short getMapIdAt(int index)
|
||||
|
@ -35,6 +35,7 @@ import java.util.ArrayDeque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Queue;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
@ -70,26 +71,7 @@ public class MapItemManager implements Listener
|
||||
|
||||
static public boolean give(Player player, PosterMap map)
|
||||
{
|
||||
short[] mapsIDs = map.getMapsIDs();
|
||||
boolean inventoryFull = false;
|
||||
|
||||
String mapName;
|
||||
for(int i = 0, c = mapsIDs.length; i < c; i++)
|
||||
{
|
||||
if(map.hasColumnData())
|
||||
{
|
||||
mapName = map.getName() +
|
||||
" (row " + map.getRowAt(i) +
|
||||
", column " + map.getColumnAt(i) + ")";
|
||||
}
|
||||
else
|
||||
{
|
||||
mapName = map.getName();
|
||||
}
|
||||
inventoryFull = give(player, createMapItem(mapsIDs[i], mapName)) || inventoryFull;
|
||||
}
|
||||
|
||||
return inventoryFull;
|
||||
return give(player, SplatterMapManager.makeSplatterMap(map));
|
||||
}
|
||||
|
||||
static public int giveCache(Player player)
|
||||
@ -154,27 +136,28 @@ public class MapItemManager implements Listener
|
||||
/**
|
||||
* Returns the item to place to display the (col;row) part of the given poster.
|
||||
*
|
||||
* @param col The column to display. Starts at 0.
|
||||
* @param row The row to display. Starts at 0.
|
||||
* @param map The map to take the part from.
|
||||
* @param x The x coordinate of the part to display. Starts at 0.
|
||||
* @param y The y coordinate of the part to display. Starts at 0.
|
||||
*
|
||||
* @return The map.
|
||||
*
|
||||
* @throws ArrayIndexOutOfBoundsException If col;row is not inside the map.
|
||||
* @throws ArrayIndexOutOfBoundsException If x;y is not inside the map.
|
||||
*/
|
||||
static public ItemStack createSubMapItem(ImageMap map, int col, int row)
|
||||
static public ItemStack createSubMapItem(ImageMap map, int x, int y)
|
||||
{
|
||||
if(map instanceof PosterMap && ((PosterMap) map).hasColumnData())
|
||||
{
|
||||
return MapItemManager.createMapItem(
|
||||
((PosterMap) map).getMapIdAt(row, col),
|
||||
((PosterMap) map).getMapIdAt(x, y),
|
||||
map.getName() +
|
||||
" (row " + (row + 1) +
|
||||
", column " + (col + 1) + ")"
|
||||
" (row " + (y + 1) +
|
||||
", column " + (x + 1) + ")"
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(row != 0 || col != 0)
|
||||
if(x != 0 || y != 0)
|
||||
{
|
||||
throw new ArrayIndexOutOfBoundsException(); // Coherence
|
||||
}
|
||||
@ -241,9 +224,15 @@ public class MapItemManager implements Listener
|
||||
|
||||
if(player.isSneaking())
|
||||
{
|
||||
if(SplatterMapManager.removeSplatterMap(frame))
|
||||
PosterMap poster = SplatterMapManager.removeSplatterMap(frame);
|
||||
if(poster != null)
|
||||
{
|
||||
event.setCancelled(true);
|
||||
if(player.getGameMode() == GameMode.CREATIVE)
|
||||
{
|
||||
if(!SplatterMapManager.hasSplatterMap(player, poster))
|
||||
poster.give(player);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -88,11 +88,10 @@ public class PosterWall
|
||||
for(int x = 0; x < map.getColumnCount(); ++x)
|
||||
{
|
||||
//Location newLocation = WorldUtils.addToLocation(topLeftLocation, x, -y, facing);
|
||||
System.out.println("Checking : " + loc);
|
||||
//System.out.println("Checking : " + loc);
|
||||
int mapIndex = map.getIndexAt(x, y);
|
||||
ItemFrame frame = getMapFrameAt(loc, map.getMapIdAt(mapIndex));
|
||||
if(frame == null) return null;
|
||||
frames[mapIndex] = frame;
|
||||
ItemFrame frame = getMapFrameAt(loc, map);
|
||||
if(frame != null) frames[mapIndex] = frame;
|
||||
loc.add(1, 0);
|
||||
}
|
||||
loc.setX(location.getX());
|
||||
@ -103,7 +102,7 @@ public class PosterWall
|
||||
return frames;
|
||||
}
|
||||
|
||||
static public ItemFrame getMapFrameAt(FlatLocation location, short mapId)
|
||||
static public ItemFrame getMapFrameAt(FlatLocation location, PosterMap map)
|
||||
{
|
||||
Entity entities[] = location.getChunk().getEntities();
|
||||
|
||||
@ -115,7 +114,7 @@ public class PosterWall
|
||||
if(frame.getFacing() != location.getFacing()) continue;
|
||||
ItemStack item = frame.getItem();
|
||||
if(item.getType() != Material.MAP) continue;
|
||||
if(item.getDurability() != mapId) continue;
|
||||
if(!map.managesMap(item)) continue;
|
||||
return frame;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
abstract public class SplatterMapManager
|
||||
@ -55,6 +56,20 @@ abstract public class SplatterMapManager
|
||||
return hasSplatterAttributes(itemStack) && MapManager.managesMap(itemStack);
|
||||
}
|
||||
|
||||
static public boolean hasSplatterMap(Player player, PosterMap map)
|
||||
{
|
||||
Inventory playerInventory = player.getInventory();
|
||||
|
||||
for(int i = 0; i < playerInventory.getSize(); ++i)
|
||||
{
|
||||
ItemStack item = playerInventory.getItem(i);
|
||||
if(isSplatterMap(item) && map.managesMap(item))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static public boolean placeSplatterMap(ItemFrame startFrame, Player player)
|
||||
{
|
||||
ImageMap map = MapManager.getMap(player.getItemInHand());
|
||||
@ -84,20 +99,20 @@ abstract public class SplatterMapManager
|
||||
return true;
|
||||
}
|
||||
|
||||
static public boolean removeSplatterMap(ItemFrame startFrame)
|
||||
static public PosterMap removeSplatterMap(ItemFrame startFrame)
|
||||
{
|
||||
ImageMap map = MapManager.getMap(startFrame.getItem());
|
||||
if(map == null || !(map instanceof PosterMap)) return false;
|
||||
if(map == null || !(map instanceof PosterMap)) return null;
|
||||
PosterMap poster = (PosterMap) map;
|
||||
FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
|
||||
ItemFrame[] matchingFrames = PosterWall.getMatchingMapFrames(poster, loc, startFrame.getItem().getDurability());
|
||||
if(matchingFrames == null) return false;
|
||||
if(matchingFrames == null) return null;
|
||||
|
||||
for(ItemFrame frame : matchingFrames)
|
||||
{
|
||||
frame.setItem(null);
|
||||
if(frame != null) frame.setItem(null);
|
||||
}
|
||||
|
||||
return true;
|
||||
return poster;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user