added map on ground/ceilling, fixed renderer bug

This commit is contained in:
valentin 2020-06-06 22:25:08 +02:00
parent f9c9049aa6
commit f79674169e
13 changed files with 209 additions and 133 deletions

View File

@ -75,34 +75,37 @@ public class NewCommand extends IoMCommand
default: throwInvalidArgument(I.t("Invalid Stretching mode.")); break; default: throwInvalidArgument(I.t("Invalid Stretching mode.")); break;
} }
} }
try {
ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("Rendering..."));
ImageRendererExecutor.render(url, scaling, player.getUniqueId(), width, height, new WorkerCallback<ImageMap>()
{
@Override
public void finished(ImageMap result)
{
ActionBar.removeMessage(player);
MessageSender.sendActionBarMessage(player, ChatColor.DARK_GREEN + I.t("Rendering finished!"));
if (result.give(player) && (result instanceof PosterMap && !((PosterMap) result).hasColumnData()))
{ ActionBar.sendPermanentMessage(player, ChatColor.DARK_GREEN + I.t("Rendering..."));
info(I.t("The rendered map was too big to fit in your inventory.")); ImageRendererExecutor.render(url, scaling, player.getUniqueId(), width, height, new WorkerCallback<ImageMap>() {
info(I.t("Use '/maptool getremaining' to get the remaining maps.")); @Override
public void finished(ImageMap result) {
ActionBar.removeMessage(player);
MessageSender.sendActionBarMessage(player, ChatColor.DARK_GREEN + I.t("Rendering finished!"));
if (result.give(player) && (result instanceof PosterMap && !((PosterMap) result).hasColumnData())) {
info(I.t("The rendered map was too big to fit in your inventory."));
info(I.t("Use '/maptool getremaining' to get the remaining maps."));
}
} }
}
@Override @Override
public void errored(Throwable exception) public void errored(Throwable exception) {
{ player.sendMessage(I.t("{ce}Map rendering failed: {0}", exception.getMessage()));
player.sendMessage(I.t("{ce}Map rendering failed: {0}", exception.getMessage()));
PluginLogger.warning("Rendering from {0} failed: {1}: {2}", PluginLogger.warning("Rendering from {0} failed: {1}: {2}",
player.getName(), player.getName(),
exception.getClass().getCanonicalName(), exception.getClass().getCanonicalName(),
exception.getMessage()); exception.getMessage());
} }
}); });
}
//Added to fix bug with rendering displaying after error
finally {
ActionBar.removeMessage(player);
}
} }
@Override @Override

View File

@ -35,6 +35,7 @@ public class ImageIOExecutor extends Worker
{ {
static public void loadImage(final File file, final Renderer mapRenderer) static public void loadImage(final File file, final Renderer mapRenderer)
{ {
submitQuery(new WorkerRunnable<Void>() submitQuery(new WorkerRunnable<Void>()
{ {
@Override @Override

View File

@ -37,7 +37,6 @@ import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@WorkerAttributes (name = "Image Renderer", queriesMainThread = true) @WorkerAttributes (name = "Image Renderer", queriesMainThread = true)
public class ImageRendererExecutor extends Worker public class ImageRendererExecutor extends Worker
{ {

View File

@ -94,4 +94,4 @@ public class ImageUtils {
graphics.dispose(); graphics.dispose();
return newImage; return newImage;
} }
} }

View File

@ -38,7 +38,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.map.MapView; import org.bukkit.map.MapView;
import java.io.File; import java.io.File;
public class MapInitEvent implements Listener public class MapInitEvent implements Listener
{ {
static public void init() static public void init()
@ -113,8 +112,10 @@ public class MapInitEvent implements Listener
static public void initMap(MapView map) static public void initMap(MapView map)
{ {
if(map == null) return; if(map == null) {
if(Renderer.isHandled(map)) return; return;}
if(Renderer.isHandled(map)) {
return;}
File imageFile = ImageOnMap.getPlugin().getImageFile(map.getId()); File imageFile = ImageOnMap.getPlugin().getImageFile(map.getId());
if(imageFile.isFile()) if(imageFile.isFile())

View File

@ -93,7 +93,6 @@ public class Renderer extends MapRenderer
{ {
//Render only once to avoid overloading the server //Render only once to avoid overloading the server
if (image == null) return; if (image == null) return;
canvas.drawImage(0, 0, image); canvas.drawImage(0, 0, image);
image = null; image = null;
} }

View File

@ -92,6 +92,7 @@ abstract public class MapManager
static public ImageMap createMap(PosterImage image, UUID playerUUID, int[] mapsIDs) throws MapManagerException static public ImageMap createMap(PosterImage image, UUID playerUUID, int[] mapsIDs) throws MapManagerException
{ {
ImageMap newMap; ImageMap newMap;
if(image.getImagesCount() == 1) if(image.getImagesCount() == 1)
{ {
newMap = new SingleMap(playerUUID, mapsIDs[0]); newMap = new SingleMap(playerUUID, mapsIDs[0]);

View File

@ -263,6 +263,7 @@ public class PlayerMapStore implements ConfigurationSerializable
try try
{ {
getToolConfig().save(mapsFile); getToolConfig().save(mapsFile);
} }
catch (IOException ex) catch (IOException ex)
{ {

View File

@ -21,8 +21,6 @@ package fr.moribus.imageonmap.map;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import fr.zcraft.zlib.tools.PluginLogger;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -132,26 +130,24 @@ public class PosterMap extends ImageMap {
return mapsIDs[y * columnCount + x]; return mapsIDs[y * columnCount + x];
} }
public int getMapIdAtReverseY(int index) { public int getMapIdAtReverseY(int index) {
int x = index % (columnCount); int x = index % (columnCount);
int y = index / (columnCount); int y = index / (columnCount);
return getMapIdAt(x, rowCount - y - 1); return getMapIdAt(x, rowCount - y - 1);
} }
public int getMapIdAtReverseZ(int index, BlockFace orientation, BlockFace bf) { public int getMapIdAtReverseZ(int index, BlockFace orientation, BlockFace bf) {
int x = 0, y = 0; int x = 0, y = 0;
switch (bf) { switch (bf) {
case UP: case UP:
x = index % (columnCount); x = index % (columnCount);
y = index / (columnCount); y = index / (columnCount);
break; break;
case DOWN: case DOWN:
x = (columnCount - 1) - index % (columnCount); x = (columnCount - 1) - index % (columnCount);
y = index / (columnCount); y = index / (columnCount);
break; break;
} }

View File

@ -229,19 +229,20 @@ public class MapItemManager implements Listener
if (frame.getItem().getType() != Material.AIR) return; if (frame.getItem().getType() != Material.AIR) return;
if (!MapManager.managesMap(mapItem)) return; if (!MapManager.managesMap(mapItem)) return;
event.setCancelled(true);
if (SplatterMapManager.hasSplatterAttributes(mapItem)) if (SplatterMapManager.hasSplatterAttributes(mapItem))
{ {
if (!SplatterMapManager.placeSplatterMap(frame, player)) if (!SplatterMapManager.placeSplatterMap(frame, player,event)){
return; event.setCancelled(true); //In case of an error allow to cancel map placement
return;}
} }
else else
{ {
// If the item has a display name, bot not one from an anvil by the player, we remove it // If the item has a display name, bot not one from an anvil by the player, we remove it
// si it is not displayed on hover on the wall. // If it is not displayed on hover on the wall.
if (mapItem.hasItemMeta() && mapItem.getItemMeta().hasDisplayName() && mapItem.getItemMeta().getDisplayName().startsWith("§r")) if (mapItem.hasItemMeta() && mapItem.getItemMeta().hasDisplayName() && mapItem.getItemMeta().getDisplayName().startsWith("§r"))
{ {
final ItemStack frameItem = mapItem.clone(); final ItemStack frameItem = mapItem.clone();
final ItemMeta meta = frameItem.getItemMeta(); final ItemMeta meta = frameItem.getItemMeta();
@ -251,9 +252,13 @@ public class MapItemManager implements Listener
frame.setItem(frameItem); frame.setItem(frameItem);
} }
else frame.setItem(mapItem); else{
frame.setItem(mapItem);
}
} }
ItemUtils.consumeItem(player); ItemUtils.consumeItem(player);
} }
@ -264,7 +269,7 @@ public class MapItemManager implements Listener
if (player.isSneaking()) if (player.isSneaking())
{ {
PosterMap poster = SplatterMapManager.removeSplatterMap(frame); PosterMap poster = SplatterMapManager.removeSplatterMap(frame,player);
if (poster != null) if (poster != null)
{ {
event.setCancelled(true); event.setCancelled(true);

View File

@ -39,33 +39,29 @@ public class PosterOnASurface {
public boolean isValid(Player p) { public boolean isValid(Player p) {
ItemFrame curFrame; ItemFrame curFrame;
PluginLogger.info("Test");
FlatLocation l = loc1.clone(); FlatLocation l = loc1.clone();
BlockFace bf = WorldUtils.get4thOrientation(p.getLocation()); BlockFace bf = WorldUtils.get4thOrientation(p.getLocation());
l.subtract(loc2); l.subtract(loc2);
;
int distX = Math.abs(l.getBlockX()); int distX = Math.abs(l.getBlockX());
int distZ = Math.abs(l.getBlockZ()); int distZ = Math.abs(l.getBlockZ());
PluginLogger.info("dist X " + distX);
PluginLogger.info("dist Z " + distZ);
frames = new ItemFrame[distX * distZ]; frames = new ItemFrame[distX * distZ];
l = loc1.clone(); l = loc1.clone();
for (int x = 0; x < distX; x++) { for (int x = 0; x < distX; x++) {
for (int z = 0; z < distZ; z++) { for (int z = 0; z < distZ; z++) {
PluginLogger.info("X=" + l.getBlockX() + " Z= " + l.getBlockZ());
PluginLogger.info(l.toString() + " " + l.getFacing().name());
curFrame = getEmptyFrameAt(l, l.getFacing()); curFrame = getEmptyFrameAt(l, l.getFacing());
if (curFrame == null) if (curFrame == null)
return false; return false;
PluginLogger.info("x " + x + " | z " + z);
frames[z * distX + x] = curFrame; frames[z * distX + x] = curFrame;
PluginLogger.info("ind frame " + z * distX + x);
switch (bf) { switch (bf) {
case NORTH: case NORTH:
@ -74,12 +70,12 @@ public class PosterOnASurface {
break; break;
case EAST: case EAST:
case WEST: case WEST:
l.addH(-1, 0, bf); l.addH(1, 0, bf);
break; break;
} }
} }
switch (bf) { switch (bf) {
case NORTH: case NORTH:
case SOUTH: case SOUTH:
@ -87,13 +83,10 @@ public class PosterOnASurface {
break; break;
case EAST: case EAST:
case WEST: case WEST:
l.addH(distX, -1, bf); l.addH(-distZ, 1, bf);
break; break;
} }
} }
return true; return true;
} }
@ -101,28 +94,76 @@ public class PosterOnASurface {
} }
/**
* Return the list of map Frames associated with a specific map
* */
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId, BlockFace bf) { static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId, BlockFace bf) {
int mapIndex = map.getIndex(mapId); int mapIndex = map.getIndex(mapId);
int x = map.getColumnAt(mapIndex), y = map.getRowAt(mapIndex); int x = map.getColumnAt(mapIndex), y = map.getRowAt(mapIndex);
return getMatchingMapFrames(map, location.clone().addH(-x, y,bf),bf); PluginLogger.info("x = "+x+" y = "+y);
return getMatchingMapFrames(map, location.clone().addH(x, y,bf),bf);
} }
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, BlockFace bf) { static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, BlockFace bf) {
ItemFrame[] frames = new ItemFrame[map.getMapCount()]; ItemFrame[] frames = new ItemFrame[map.getMapCount()];
FlatLocation loc = location.clone(); FlatLocation loc = location.clone();
for (int y = 0; y < map.getRowCount(); ++y) { PluginLogger.info("loc = "+location+ " bf = "+bf);
for (int x = 0; x < map.getColumnCount(); ++x) {
int X=0;
int Y=0;
switch (bf){
case EAST:
case WEST:
/* X=map.getRowCount();
Y=map.getColumnCount();
break;*/
case NORTH:
case SOUTH:
Y=map.getRowCount();
X=map.getColumnCount();
break;
}
PluginLogger.info("max: X: "+X+" Y:"+Y);
for (int y = 0; y < Y; ++y) {
for (int x = 0; x < X; ++x) {
PluginLogger.info("x: "+x+" y:"+y);
int mapIndex = map.getIndexAt(x, y); int mapIndex = map.getIndexAt(x, y);
PluginLogger.info("map index "+mapIndex);
//PluginLogger.info("loc= "+loc);
ItemFrame frame = getMapFrameAt(loc, map); ItemFrame frame = getMapFrameAt(loc, map);
PluginLogger.info("frame= "+frame.getLocation());
if (frame != null) if (frame != null)
frames[mapIndex] = frame; frames[mapIndex] = frame;
loc.add(1, 0); switch (bf){
case EAST:
case WEST:
loc.addH( 0,1,bf);
break;
case NORTH:
case SOUTH:
loc.addH( 1,0,bf);
break;
}
} }
loc.setX(location.getX());
loc.setZ(location.getZ()); switch (bf){
loc.addH(0, -1,bf); case EAST:
case WEST:
loc.addH( -1,-map.getRowCount(),bf);//test
//loc.addH( -map.getRowCount(),-1,bf);
break;
case NORTH:
case SOUTH:
loc.addH(-map.getColumnCount(), -1,bf);
break;
}
} }
return frames; return frames;

View File

@ -19,7 +19,6 @@
package fr.moribus.imageonmap.ui; package fr.moribus.imageonmap.ui;
import fr.moribus.imageonmap.map.PosterMap; import fr.moribus.imageonmap.map.PosterMap;
import fr.zcraft.zlib.tools.PluginLogger;
import fr.zcraft.zlib.tools.world.FlatLocation; import fr.zcraft.zlib.tools.world.FlatLocation;
import fr.zcraft.zlib.tools.world.WorldUtils; import fr.zcraft.zlib.tools.world.WorldUtils;
import org.bukkit.Location; import org.bukkit.Location;
@ -45,9 +44,7 @@ public class PosterWall
int distX = FlatLocation.flatBlockDistanceX(loc1, loc2); int distX = FlatLocation.flatBlockDistanceX(loc1, loc2);
int distY = FlatLocation.flatBlockDistanceY(loc1, loc2); int distY = FlatLocation.flatBlockDistanceY(loc1, loc2);
PluginLogger.info("dist X "+distX);
PluginLogger.info("dist Y "+distY);
frames = new ItemFrame[distX * distY]; frames = new ItemFrame[distX * distY];
for(int x = 0; x < distX; x++) for(int x = 0; x < distX; x++)
@ -68,9 +65,7 @@ public class PosterWall
public void expand() public void expand()
{ {
} }
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId) static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId)

View File

@ -34,7 +34,6 @@ import fr.zcraft.zlib.tools.reflection.NMSException;
import fr.zcraft.zlib.tools.text.MessageSender; import fr.zcraft.zlib.tools.text.MessageSender;
import fr.zcraft.zlib.tools.world.FlatLocation; import fr.zcraft.zlib.tools.world.FlatLocation;
import fr.zcraft.zlib.tools.world.WorldUtils; import fr.zcraft.zlib.tools.world.WorldUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.Material; import org.bukkit.Material;
@ -42,6 +41,7 @@ import org.bukkit.Rotation;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta; import org.bukkit.inventory.meta.MapMeta;
@ -51,6 +51,12 @@ abstract public class SplatterMapManager {
} }
static public ItemStack makeSplatterMap(PosterMap map) { static public ItemStack makeSplatterMap(PosterMap map) {
String s="";
for(Byte b:I.t("Splatter Map").getBytes()){
s+=b+" ";
}
PluginLogger.info(""+s);
final ItemStack splatter = new ItemStackBuilder(Material.FILLED_MAP).title(ChatColor.GOLD, map.getName()) final ItemStack splatter = new ItemStackBuilder(Material.FILLED_MAP).title(ChatColor.GOLD, map.getName())
.title(ChatColor.DARK_GRAY, " - ").title(ChatColor.GRAY, I.t("Splatter Map")) .title(ChatColor.DARK_GRAY, " - ").title(ChatColor.GRAY, I.t("Splatter Map"))
.title(ChatColor.DARK_GRAY, " - ") .title(ChatColor.DARK_GRAY, " - ")
@ -145,10 +151,19 @@ abstract public class SplatterMapManager {
} }
} }
/**
* Return true if it is a platter map
*
* @param itemStack
* The item to check.
* @return True if is a splatter map
*/
static public boolean isSplatterMap(ItemStack itemStack) { static public boolean isSplatterMap(ItemStack itemStack) {
return hasSplatterAttributes(itemStack) && MapManager.managesMap(itemStack); return hasSplatterAttributes(itemStack) && MapManager.managesMap(itemStack);
} }
//TODO doc a faire
static public boolean hasSplatterMap(Player player, PosterMap map) { static public boolean hasSplatterMap(Player player, PosterMap map) {
Inventory playerInventory = player.getInventory(); Inventory playerInventory = player.getInventory();
@ -161,90 +176,93 @@ abstract public class SplatterMapManager {
return false; return false;
} }
static public boolean placeSplatterMap(ItemFrame startFrame, Player player) { /**
* Place a splatter map
*
* @param startFrame
* Frame clicked by the player
* @param player
* Player placing map
* @return true if the map was correctly placed
*/
static public boolean placeSplatterMap(ItemFrame startFrame, Player player, PlayerInteractEntityEvent event) {
ImageMap map = MapManager.getMap(player.getInventory().getItemInMainHand()); ImageMap map = MapManager.getMap(player.getInventory().getItemInMainHand());
if (!(map instanceof PosterMap)) if (!(map instanceof PosterMap))
return false; return false;
PosterMap poster = (PosterMap) map; PosterMap poster = (PosterMap) map;
PosterWall wall = new PosterWall(); PosterWall wall = new PosterWall();
// NEW
if (startFrame.getFacing().equals(BlockFace.DOWN) || startFrame.getFacing().equals(BlockFace.UP)) {
PluginLogger.info("UP or DOWN ");
if (startFrame.getFacing().equals(BlockFace.DOWN) || startFrame.getFacing().equals(BlockFace.UP)) {
// If it is on floor or ceiling
PosterOnASurface surface = new PosterOnASurface(); PosterOnASurface surface = new PosterOnASurface();
FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing()); FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
FlatLocation endLocation = startLocation.clone().addH(poster.getColumnCount(), poster.getRowCount(), FlatLocation endLocation = startLocation.clone().addH(poster.getColumnCount(), poster.getRowCount(),
WorldUtils.get4thOrientation(player.getLocation())); WorldUtils.get4thOrientation(player.getLocation()));
PluginLogger.info("Before loc asign ");
surface.loc1 = startLocation; surface.loc1 = startLocation;
surface.loc2 = endLocation; surface.loc2 = endLocation;
PluginLogger.info("After loc asign ");
// todo impletation
if (!surface.isValid(player)) { if (!surface.isValid(player)) {
MessageSender.sendActionBarMessage(player, MessageSender.sendActionBarMessage(player,
I.t("{ce}There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(), I.t("{ce}There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(),
poster.getRowCount())); poster.getRowCount()));
return false; return false;
} }
int i = 0; int i = 0;
for (ItemFrame frame : surface.frames) { for (ItemFrame frame : surface.frames) {
PluginLogger.info("Test " + frame.getName());
BlockFace bf = WorldUtils.get4thOrientation(player.getLocation()); BlockFace bf = WorldUtils.get4thOrientation(player.getLocation());
int id = poster.getMapIdAtReverseZ(i, bf, startFrame.getFacing()); int id = poster.getMapIdAtReverseZ(i, bf, startFrame.getFacing());
Rotation rot = Rotation.NONE;
Rotation rot = frame.getRotation(); switch(frame.getFacing()){
case UP:
// NESW break;
//PluginLogger.info("ordinal " + rot.ordinal() ); case DOWN:
/*switch(bf){ rot = Rotation.FLIPPED;
case NORTH: break;
frame.setRotation(Rotation.NONE);
break;
case EAST:
frame.setRotation(Rotation.CLOCKWISE);
break;
case SOUTH:
frame.setRotation(Rotation.FLIPPED);
break;
case WEST:
frame.setRotation(Rotation.COUNTER_CLOCKWISE);
break;
}*/
PluginLogger.info("bf ordinal "+ bf.ordinal());
while (rot.ordinal() != 2*bf.ordinal()) {
rot = rot.rotateClockwise();
//PluginLogger.info("Rotation ordinal " + rot.ordinal() + " bf ordinal " + bf.ordinal());
frame.setRotation(rot);
} }
switch (bf) { //Rotation management relative to player rotation the default position is North, when on ceiling we flipped the rotation
case UP:
frame.setRotation(rot);
break;
case DOWN:
rot=rot.rotateClockwise().rotateClockwise();
frame.setRotation(rot);
break;
}
rot = frame.getRotation();
//PluginLogger.info("ordinal " + rot.ordinal() );
frame.setItem(new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem()); frame.setItem(new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem());
frame.setRotation(Rotation.CLOCKWISE);
switch(bf) {
case NORTH:
if(frame.getFacing()==BlockFace.DOWN){
rot = rot.rotateClockwise();
rot = rot.rotateClockwise();
}
frame.setRotation(rot);
break;
case EAST:
rot = rot.rotateClockwise();
frame.setRotation(rot);
break;
case SOUTH:
if(frame.getFacing()==BlockFace.UP){
rot = rot.rotateClockwise();
rot = rot.rotateClockwise();
}
frame.setRotation(rot);
break;
case WEST:
rot = rot.rotateCounterClockwise();
frame.setRotation(rot);
break;
}
MapInitEvent.initMap(id); MapInitEvent.initMap(id);
++i; i++;
} }
} else { } else {
// If it is on a wall NSEW
FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing()); FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
FlatLocation endLocation = startLocation.clone().add(poster.getColumnCount(), poster.getRowCount()); FlatLocation endLocation = startLocation.clone().add(poster.getColumnCount(), poster.getRowCount());
wall.loc1 = startLocation; wall.loc1 = startLocation;
wall.loc2 = endLocation; wall.loc2 = endLocation;
PluginLogger.info("startLocation " + startLocation + " | endLocation " + endLocation);
if (!wall.isValid()) { if (!wall.isValid()) {
MessageSender.sendActionBarMessage(player, MessageSender.sendActionBarMessage(player,
I.t("{ce}There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(), I.t("{ce}There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(),
@ -254,8 +272,15 @@ abstract public class SplatterMapManager {
int i = 0; int i = 0;
for (ItemFrame frame : wall.frames) { for (ItemFrame frame : wall.frames) {
int id = poster.getMapIdAtReverseY(i); int id = poster.getMapIdAtReverseY(i);
frame.setItem(new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem()); frame.setItem(new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem());
//Force reset of rotation
if(i==0){//First map need to be rotate one time Clockwise
frame.setRotation(Rotation.NONE.rotateCounterClockwise());
}
else{frame.setRotation(Rotation.NONE);}
MapInitEvent.initMap(id); MapInitEvent.initMap(id);
++i; ++i;
} }
@ -263,7 +288,16 @@ abstract public class SplatterMapManager {
return true; return true;
} }
static public PosterMap removeSplatterMap(ItemFrame startFrame) { /**
* Remove splattermap
*
* @param startFrame
* Frame clicked by the player
* @param player
* The player removing the map
* @return
*/
static public PosterMap removeSplatterMap(ItemFrame startFrame, Player player) {
final ImageMap map = MapManager.getMap(startFrame.getItem()); final ImageMap map = MapManager.getMap(startFrame.getItem());
if (!(map instanceof PosterMap)) if (!(map instanceof PosterMap))
return null; return null;
@ -272,21 +306,21 @@ abstract public class SplatterMapManager {
return null; return null;
FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing()); FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
ItemFrame[] matchingFrames=null; ItemFrame[] matchingFrames=null;
switch(startFrame.getFacing()){ switch(startFrame.getFacing()){
case UP: case UP:
case DOWN: case DOWN:
matchingFrames = PosterOnASurface.getMatchingMapFrames(poster, loc, matchingFrames = PosterOnASurface.getMatchingMapFrames(poster, loc,
MapManager.getMapIdFromItemStack(startFrame.getItem()),startFrame.getFacing()); MapManager.getMapIdFromItemStack(startFrame.getItem()),WorldUtils.get4thOrientation(player.getLocation()));//startFrame.getFacing());
break; break;
case NORTH:
case SOUTH: case NORTH:
case EAST: case SOUTH:
case WEST: case EAST:
matchingFrames = PosterWall.getMatchingMapFrames(poster, loc, case WEST:
matchingFrames = PosterWall.getMatchingMapFrames(poster, loc,
MapManager.getMapIdFromItemStack(startFrame.getItem())); MapManager.getMapIdFromItemStack(startFrame.getItem()));
} }
if (matchingFrames == null) if (matchingFrames == null)
return null; return null;