dithering floyd (partial don't work properly)

This commit is contained in:
Vlammar 2020-07-08 20:06:43 +02:00
parent 219869c82b
commit 97af1a8080
8 changed files with 672 additions and 382 deletions

View File

@ -120,6 +120,9 @@ public class NewCommand extends IoMCommand
}
});
}
catch(final Throwable e){
throw e;
}
//Added to fix bug with rendering displaying after error
finally {
ActionBar.removeMessage(player);

View File

@ -38,6 +38,7 @@ package fr.moribus.imageonmap.image;
import fr.moribus.imageonmap.ImageOnMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.ui.SplatterMapManager;
import fr.zcraft.zlib.core.ZLib;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -47,9 +48,11 @@ import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.ItemStack;
@ -114,7 +117,56 @@ public class MapInitEvent implements Listener
initMap(event.getCursor());
}
}
@EventHandler(priority = EventPriority.HIGHEST)
private void onInventoryClick(InventoryClickEvent event) {
//Checks if they have clicked anywhere else on the screen while an inventory is open
if(event.getClickedInventory() == null) return;
//Checks if the clicked slot is empty
if(event.getClickedInventory().getItem(event.getSlot()) == null) return;
//Forbid deposit of map in unwanted block
if(event.getInventory().getType().name().equals("GRINDSTONE") & SplatterMapManager.isSplatterMap(event.getCurrentItem())){
event.setCancelled(true);
return;
}
//To cancel removing of glowing effect
if(event.getClickedInventory().getSize()==3) {
String inventoryClickedTitle=event.getClickedInventory().getType().name();
//Ignore those blocks
if(event.getClickedInventory().getType()== InventoryType.ANVIL||event.getClickedInventory().getType()==InventoryType.FURNACE||inventoryClickedTitle.equals("BLAST_FURNACE")||inventoryClickedTitle.equals("SMOKER")){
return;
}
if(inventoryClickedTitle.equals("CARTOGRAPHY_TABLE")){
if(event.getInventory().contains(Material.PAPER)){
ItemStack[] inventory=event.getClickedInventory().getContents();
for(ItemStack item:inventory) {
if (SplatterMapManager.isSplatterMap(item)) {
event.setCancelled(true);
return;
}
}
}
}
ItemStack[] inventory=event.getClickedInventory().getContents();
for(ItemStack item:inventory){
if (SplatterMapManager.isSplatterMap(item)) {
event.setCancelled(true);
return;
}
}
}
}
static public void initMap(ItemStack item)
{
if (item != null && item.getType() == Material.FILLED_MAP)

View File

@ -40,88 +40,280 @@ import fr.zcraft.zlib.tools.PluginLogger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.map.MapCanvas;
import org.bukkit.map.MapPalette;
import org.bukkit.map.MapRenderer;
import org.bukkit.map.MapView;
import java.awt.*;
import java.awt.image.BufferedImage;
public class Renderer extends MapRenderer
{
static public boolean isHandled(MapView map)
{
if(map == null) return false;
for(MapRenderer renderer : map.getRenderers())
{
if(renderer instanceof Renderer) return true;
public class Renderer extends MapRenderer {
private BufferedImage image;
protected Renderer() {
this(null);
}
protected Renderer(BufferedImage image) {
this.image = image;
}
static public boolean isHandled(MapView map) {
if (map == null) return false;
for (MapRenderer renderer : map.getRenderers()) {
if (renderer instanceof Renderer) return true;
}
return false;
}
static public void installRenderer(PosterImage image, int[] mapsIds)
{
for(int i = 0; i < mapsIds.length; i++)
{
static public void installRenderer(PosterImage image, int[] mapsIds) {
for (int i = 0; i < mapsIds.length; i++) {
installRenderer(image.getImageAt(i), mapsIds[i]);
}
}
static public void installRenderer(BufferedImage image, int mapID)
{
static public void installRenderer(BufferedImage image, int mapID) {
MapView map = Bukkit.getMap(mapID);
if(map == null)
{
if (map == null) {
PluginLogger.warning("Could not install renderer for map {0}: the Minecraft map does not exist", mapID);
}
else
{
} else {
installRenderer(map).setImage(image);
}
}
static public Renderer installRenderer(MapView map)
{
static public Renderer installRenderer(MapView map) {
Renderer renderer = new Renderer();
removeRenderers(map);
map.addRenderer(renderer);
return renderer;
}
static public void removeRenderers(MapView map)
{
for(MapRenderer renderer : map.getRenderers())
{
static public void removeRenderers(MapView map) {
for (MapRenderer renderer : map.getRenderers()) {
map.removeRenderer(renderer);
}
}
private BufferedImage image;
protected Renderer()
{
this(null);
private static double getDistance(Color c1, Color c2) {
double rmean = (c1.getRed() + c2.getRed()) / 2.0;
double r = c1.getRed() - c2.getRed();
double g = c1.getGreen() - c2.getGreen();
int b = c1.getBlue() - c2.getBlue();
double weightR = 2 + rmean / 256.0;
double weightG = 4.0;
double weightB = 2 + (255 - rmean) / 256.0;
return weightR * r * r + weightG * g * g + weightB * b * b;
}
protected Renderer(BufferedImage image)
{
this.image = image;
private byte closestColor(int rgb) {
int alpha = (rgb >>> 24) & 0xFF;
int r = (rgb >>> 16) & 0xFF;
int g = (rgb >>> 8) & 0xFF;
int b = rgb & 0xFF;
byte col = MapPalette.matchColor(new Color(r, g, b, alpha));
return col;
}
protected class RGB{
private int alpha,r,g,b;
public RGB(int r, int g, int b,int alpha){
this.r=r;
this.g=g;
this.b=b;
this.alpha=alpha;
}
public RGB(int rgb){
int alpha = (rgb >>> 24) & 0xFF;
int r = (rgb >>> 16) & 0xFF;
int g = (rgb >>> 8) & 0xFF;
int b = rgb & 0xFF;
this.r=r;
this.g=g;
this.b=b;
this.alpha=alpha;
}
public RGB(int r, int g, int b){
this.r=r;
this.g=g;
this.b=b;
this.alpha=255;
}
public void applyFactor(double factor){
r*=factor;
g*=factor;
b*=factor;
}
}
private void dithering(MapCanvas canvas) {
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 128; y++) {
int rgb = image.getRGB(x, y);
Color old_pix = new Color(rgb);
Color new_pix = MapPalette.getColor(MapPalette.matchColor(old_pix));//Couleur la plus proche
int alpha = (rgb >>> 24) & 0xFF;
if (alpha < 128) {
canvas.setPixel(x, y, (byte) 0);
continue;
}
canvas.setPixel(x, y, MapPalette.matchColor(new_pix));//On applique la nouvelle couleur
int diff_red=old_pix.getRed()-new_pix.getRed();
int diff_green=old_pix.getGreen()-new_pix.getGreen();
int diff_blue=old_pix.getBlue()-new_pix.getBlue();
//Distribution de l'erreur
int X = 0, Y = 0, r, g, b;
int value = 0;//120+4+4+7*4+24+1+16;//208+10*4+4;
if (x + 1 >= 128 | y + 1 >= 128 | x - 1 < 0) {
//PluginLogger.info("On va trop loin");
canvas.setPixel(x, y, (byte) 20);//MapPalette.matchColor(new_pix));
continue;
}
double factor;
try {
X = x + 1;
Y = y;
factor=7.0/16;
rgb=(MapPalette.getColor(canvas.getPixel(X, Y) < 0 ? (byte) (canvas.getPixel(x, y) + value) : canvas.getPixel(x, y)).getRGB());
//rgb = (int) ((MapPalette.getColor(canvas.getPixel(X, Y) < 0 ? (byte) (canvas.getPixel(x, y) + value) : canvas.getPixel(x, y)).getRGB()) + (error * 7.0 / 16));
alpha = (rgb >>> 24) & 0xFF;
r = (rgb >>> 16) & 0xFF;
g = (rgb >>> 8) & 0xFF;
b = rgb & 0xFF;
r+=diff_red*factor;
g+=diff_green*factor;
b+=diff_blue*factor;
if (alpha < 128)
canvas.setPixel(x, y, (byte) 0);
else
canvas.setPixel(x, y, MapPalette.matchColor(r, g, b));//Pb possible avec alpha
X = x - 1;
Y = y + 1;
factor=3.0/16;
rgb=(MapPalette.getColor(canvas.getPixel(X, Y) < 0 ? (byte) (canvas.getPixel(x, y) + value) : canvas.getPixel(x, y)).getRGB());
//rgb = (int) ((MapPalette.getColor(canvas.getPixel(X, Y) < 0 ? (byte) (canvas.getPixel(x, y) + value) : canvas.getPixel(x, y)).getRGB()) + (error * 3.0 / 16));
alpha = (rgb >>> 24) & 0xFF;
r = (rgb >>> 16) & 0xFF;
g = (rgb >>> 8) & 0xFF;
b = rgb & 0xFF;
r+=diff_red*factor;
g+=diff_green*factor;
b+=diff_blue*factor;
if (alpha < 128)
canvas.setPixel(x, y, (byte) 0);
else
canvas.setPixel(x, y, MapPalette.matchColor(r, g, b));//Pb possible avec alpha
X = x;
Y = y + 1;
factor=5.0/16;
rgb=(MapPalette.getColor(canvas.getPixel(X, Y) < 0 ? (byte) (canvas.getPixel(x, y) + value) : canvas.getPixel(x, y)).getRGB());
//rgb = (int) ((MapPalette.getColor(canvas.getPixel(X, Y) < 0 ? (byte) (canvas.getPixel(x, y) + value) : canvas.getPixel(x, y)).getRGB()) + (error * 5.0 / 16));
alpha = (rgb >>> 24) & 0xFF;
r = (rgb >>> 16) & 0xFF;
g = (rgb >>> 8) & 0xFF;
b = rgb & 0xFF;
r+=diff_red*factor;
g+=diff_green*factor;
b+=diff_blue*factor;
if (alpha < 128)
canvas.setPixel(x, y, (byte) 0);
else
canvas.setPixel(x, y, MapPalette.matchColor(r, g, b));//Pb possible avec alpha
X = x + 1;
Y = y + 1;
factor=1.0/16;
rgb=(MapPalette.getColor(canvas.getPixel(X, Y) < 0 ? (byte) (canvas.getPixel(x, y) + value) : canvas.getPixel(x, y)).getRGB());
//rgb = (int) ((MapPalette.getColor(canvas.getPixel(X, Y) < 0 ? (byte) (canvas.getPixel(x, y) + value) : canvas.getPixel(x, y)).getRGB()) + (error * 1.0 / 16));
alpha = (rgb >>> 24) & 0xFF;
r = (rgb >>> 16) & 0xFF;
g = (rgb >>> 8) & 0xFF;
b = rgb & 0xFF;
int rold = r;
int gold = g;
int bold = b;
r+=diff_red*factor;
g+=diff_green*factor;
b+=diff_blue*factor;
if (alpha < 128)
canvas.setPixel(x, y, (byte) 0);
else
canvas.setPixel(x, y, MapPalette.matchColor(r, g, b));//Pb possible avec alpha
// PluginLogger.info("r "+r+" g "+g+" b "+b);
//PluginLogger.info("rold "+rold+" gold "+gold+" bold "+bold);
} catch (final Exception e) {
PluginLogger.info("Exception get color ");
throw e;
}
//canvas.setPixel(x-1,y+1,canvas.getPixel(x-1,y+1)+(error*7.0/16));
//canvas.setPixel(x,y+1,canvas.getPixel(x,y+1)+(error*7.0/16));
//canvas.setPixel(x+1,y+1,canvas.getPixel(x+1,y+1)+(error*7.0/16));
}
}
}
@Override
public void render(MapView v, final MapCanvas canvas, Player p)
{
public void render(MapView v, MapCanvas canvas, Player p) {
//Render only once to avoid overloading the server
if (image == null) return;
canvas.drawImage(0, 0, image);
image = null;
boolean dither = true;
// canvas.drawImage(0, 0, image);
if (dither) {
dithering(canvas);
return;
}
for (int x = 0; x < 128; x++) {
for (int y = 0; y < 128; y++) {
int rgb = image.getRGB(x, y);
byte col = closestColor(rgb);
canvas.setPixel(x, y, col);
}
}
public BufferedImage getImage()
{
/* for(int x=0;x<128;x++){
for(int y=0;y<128;y++){
int rgb=image.getRGB(x,y);
int r = (rgb >>> 16) & 0xFF;
int g = (rgb >>> 8) & 0xFF;
int b = rgb & 0xFF;
//PluginLogger.info("canvas pixel "+x+" "+y+" r "+r+" g "+g+" b "+b);
PluginLogger.info(""+canvas.getBasePixel(x,y));
canvas.setPixel(x,y,(byte)208);
}*/
image = null;
}
public BufferedImage getImage() {
return image;
}
public void setImage(BufferedImage image)
{
public void setImage(BufferedImage image) {
this.image = image;
}
}

View File

@ -126,12 +126,20 @@ abstract public class MapManager
static public int[] getNewMapsIds(int amount)
{
int[] mapsIds = new int[amount];
for(int i = 0; i < amount; i++)
{
try {
for (int i = 0; i < amount; i++) {
mapsIds[i] = Bukkit.createMap(Bukkit.getWorlds().get(0)).getId();
}
return mapsIds;
}
catch (final Throwable e){
PluginLogger.warning("Erreur a la creation de map !!!");
throw e;
}
}
/**
* Returns the map ID from an ItemStack
@ -140,12 +148,15 @@ abstract public class MapManager
*/
static public int getMapIdFromItemStack(final ItemStack item)
{
final ItemMeta meta = item.getItemMeta();
if (!(meta instanceof MapMeta)) return 0;
return ((MapMeta) meta).hasMapId() ? ((MapMeta) meta).getMapId() : 0;
}
static public void addMap(ImageMap map) throws MapManagerException
{
getPlayerMapStore(map.getUserUUID()).addMap(map);

View File

@ -36,12 +36,14 @@
package fr.moribus.imageonmap.ui;
import fr.moribus.imageonmap.Permissions;
import fr.moribus.imageonmap.map.ImageMap;
import fr.moribus.imageonmap.map.MapManager;
import fr.moribus.imageonmap.map.PosterMap;
import fr.moribus.imageonmap.map.SingleMap;
import fr.zcraft.zlib.components.i18n.I;
import fr.zcraft.zlib.core.ZLib;
import fr.zcraft.zlib.tools.PluginLogger;
import fr.zcraft.zlib.tools.items.ItemStackBuilder;
import fr.zcraft.zlib.tools.items.ItemUtils;
import org.bukkit.*;
@ -271,6 +273,7 @@ public class MapItemManager implements Listener
}
else{
PluginLogger.info("Coucou je suis une carte simple");
frame.setItem(mapItem);
}
@ -285,6 +288,8 @@ public class MapItemManager implements Listener
ItemStack item = frame.getItem();
if (frame.getItem().getType() != Material.FILLED_MAP) return;
if (Permissions.REMOVE_SPLATTER_MAP.grantedTo(player))
{
if (player.isSneaking())
{
PosterMap poster = SplatterMapManager.removeSplatterMap(frame,player);
@ -298,6 +303,7 @@ public class MapItemManager implements Listener
return;
}
}
}
if (!MapManager.managesMap(frame.getItem())) return;

View File

@ -107,6 +107,7 @@ public class PosterOnASurface {
return true;
}
//If in creative expand item frames in order to auto deploy
public void expand() {
}

View File

@ -43,69 +43,82 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ItemFrame;
import org.bukkit.inventory.ItemStack;
public class PosterWall
{
public class PosterWall {
public FlatLocation loc1;
public FlatLocation loc2;
public ItemFrame[] frames;
public boolean isValid()
{
ItemFrame curFrame;
FlatLocation bottomLeft = FlatLocation.minMerged(loc1, loc2);
FlatLocation loc = bottomLeft.clone();
int distX = FlatLocation.flatBlockDistanceX(loc1, loc2);
int distY = FlatLocation.flatBlockDistanceY(loc1, loc2);
frames = new ItemFrame[distX * distY];
for(int x = 0; x < distX; x++)
{
for(int y = 0; y < distY; y++)
{
curFrame = getEmptyFrameAt(loc, loc.getFacing());
if(curFrame == null) return false;
frames[y * distX + x] = curFrame;
loc.add(0, 1);
private static boolean supportIsValid(FlatLocation location, BlockFace bf, int width, int height) {
//Code to add
FlatLocation loc=location.clone();
loc.add(0,-1);
switch (bf){
case EAST:
case WEST:
loc.addH(1,0,bf);
break;
case NORTH:
case SOUTH:
loc.addH(0,1,bf);
break;
}
loc.add(1, 0);
loc.setY(bottomLeft.getY());
}
return true;
}
public void expand()
{
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
// if(loc.getBlock().)
}
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId)
{
}
return false;
}
//Used to expand itemframes when possible
public static void expand(FlatLocation location,BlockFace bf ,int width, int height) throws Exception{
if (!supportIsValid(location,bf, width, height))
return;
FlatLocation loc=location.clone();
loc.add(0,-1);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
loc.add(0,1);
loc.getWorld().spawnEntity(loc, EntityType.ITEM_FRAME);
}
loc.add(1,-height);
}
}
/*static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId, Player p) {
if (p.getGameMode() == GameMode.CREATIVE)
expand(location, map.getColumnCount(), map.getRowCount());
return getMatchingMapFrames(map, location, mapId);
}*/
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId) {
int mapIndex = map.getIndex(mapId);
int x = map.getColumnAt(mapIndex), y = map.getRowAt(mapIndex);
return getMatchingMapFrames(map, location.clone().add(-x, y));
}
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location)
{
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location) {
ItemFrame[] frames = new ItemFrame[map.getMapCount()];
FlatLocation loc = location.clone();
for(int y = 0; y < map.getRowCount(); ++y)
{
for(int x = 0; x < map.getColumnCount(); ++x)
{
for (int y = 0; y < map.getRowCount(); ++y) {
for (int x = 0; x < map.getColumnCount(); ++x) {
int mapIndex = map.getIndexAt(x, y);
ItemFrame frame = getMapFrameAt(loc, map);
if(frame != null) frames[mapIndex] = frame;
if (frame != null) frames[mapIndex] = frame;
loc.add(1, 0);
}
loc.setX(location.getX());
@ -116,40 +129,60 @@ public class PosterWall
return frames;
}
static public ItemFrame getMapFrameAt(FlatLocation location, PosterMap map)
{
static public ItemFrame getMapFrameAt(FlatLocation location, PosterMap map) {
Entity entities[] = location.getChunk().getEntities();
for(Entity entity : entities)
{
if(!(entity instanceof ItemFrame)) continue;
if(!WorldUtils.blockEquals(location, entity.getLocation())) continue;
for (Entity entity : entities) {
if (!(entity instanceof ItemFrame)) continue;
if (!WorldUtils.blockEquals(location, entity.getLocation())) continue;
ItemFrame frame = (ItemFrame) entity;
if(frame.getFacing() != location.getFacing()) continue;
if (frame.getFacing() != location.getFacing()) continue;
ItemStack item = frame.getItem();
if(item.getType() != Material.FILLED_MAP) continue;
if(!map.managesMap(item)) continue;
if (item.getType() != Material.FILLED_MAP) continue;
if (!map.managesMap(item)) continue;
return frame;
}
return null;
}
static public ItemFrame getEmptyFrameAt(Location location, BlockFace facing)
{
static public ItemFrame getEmptyFrameAt(Location location, BlockFace facing) {
Entity entities[] = location.getChunk().getEntities();
for(Entity entity : entities)
{
if(!(entity instanceof ItemFrame)) continue;
if(!WorldUtils.blockEquals(location, entity.getLocation())) continue;
for (Entity entity : entities) {
if (!(entity instanceof ItemFrame)) continue;
if (!WorldUtils.blockEquals(location, entity.getLocation())) continue;
ItemFrame frame = (ItemFrame) entity;
if(frame.getFacing() != facing) continue;
if (frame.getFacing() != facing) continue;
ItemStack item = frame.getItem();
if(item.getType() != Material.AIR) continue;
if (item.getType() != Material.AIR) continue;
return frame;
}
return null;
}
public boolean isValid() {
ItemFrame curFrame;
FlatLocation bottomLeft = FlatLocation.minMerged(loc1, loc2);
FlatLocation loc = bottomLeft.clone();
int distX = FlatLocation.flatBlockDistanceX(loc1, loc2);
int distY = FlatLocation.flatBlockDistanceY(loc1, loc2);
frames = new ItemFrame[distX * distY];
for (int x = 0; x < distX; x++) {
for (int y = 0; y < distY; y++) {
curFrame = getEmptyFrameAt(loc, loc.getFacing());
if (curFrame == null) return false;
frames[y * distX + x] = curFrame;
loc.add(0, 1);
}
loc.add(1, 0);
loc.setY(bottomLeft.getY());
}
return true;
}
}

View File

@ -52,10 +52,7 @@ import fr.zcraft.zlib.tools.reflection.NMSException;
import fr.zcraft.zlib.tools.text.MessageSender;
import fr.zcraft.zlib.tools.world.FlatLocation;
import fr.zcraft.zlib.tools.world.WorldUtils;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Rotation;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
@ -64,6 +61,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta;
abstract public class SplatterMapManager {
private SplatterMapManager() {
}
@ -71,7 +69,6 @@ abstract public class SplatterMapManager {
static public ItemStack makeSplatterMap(PosterMap map) {
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, " - ")
@ -106,18 +103,17 @@ abstract public class SplatterMapManager {
/**
* To identify image on maps for the auto-splattering to work, we mark the
* items using an enchantment maps are not supposed to have (Mending).
*
* <p>
* Then we check if the map is enchanted at all to know if it's a splatter
* map. This ensure compatibility with old splatter maps from 3.x, where
* zLib's glow effect was used.
*
* <p>
* An AttributeModifier (using zLib's attributes system) is not used,
* because Minecraft (or Spigot) removes them from maps in 1.14+, so that
* wasn't stable enough (and the glowing effect of enchantments is
* prettier).
*
* @param itemStack
* The item stack to mark as a splatter map.
* @param itemStack The item stack to mark as a splatter map.
* @return The modified item stack. The instance may be different if the
* passed item stack is not a craft item stack; that's why the
* instance is returned.
@ -145,8 +141,7 @@ abstract public class SplatterMapManager {
* Checks if an item have the splatter attribute set (i.e. if the item is
* enchanted in any way).
*
* @param itemStack
* The item to check.
* @param itemStack The item to check.
* @return True if the attribute was detected.
*/
static public boolean hasSplatterAttributes(ItemStack itemStack) {
@ -167,12 +162,11 @@ abstract public class SplatterMapManager {
/**
* Return true if it is a platter map
*
* @param itemStack
* The item to check.
* @param itemStack The item to check.
* @return True if is a splatter map
*/
static public boolean isSplatterMap(ItemStack itemStack) {
if(itemStack==null) return false;
if (itemStack == null) return false;
return hasSplatterAttributes(itemStack) && MapManager.managesMap(itemStack);
}
@ -193,10 +187,8 @@ abstract public class SplatterMapManager {
/**
* Place a splatter map
*
* @param startFrame
* Frame clicked by the player
* @param player
* Player placing 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) {
@ -231,7 +223,7 @@ abstract public class SplatterMapManager {
BlockFace bf = WorldUtils.get4thOrientation(player.getLocation());
int id = poster.getMapIdAtReverseZ(i, bf, startFrame.getFacing());
Rotation rot = Rotation.NONE;
switch(frame.getFacing()){
switch (frame.getFacing()) {
case UP:
break;
case DOWN:
@ -240,8 +232,8 @@ abstract public class SplatterMapManager {
}
//Rotation management relative to player rotation the default position is North, when on ceiling we flipped the rotation
frame.setItem(new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem());
if(i==0){//First map need to be rotate one time CounterClockwise
rot=rot.rotateCounterClockwise();
if (i == 0) {//First map need to be rotate one time CounterClockwise
rot = rot.rotateCounterClockwise();
}
switch (bf) {
@ -269,17 +261,18 @@ abstract public class SplatterMapManager {
break;
}
WorldMap
MapInitEvent.initMap(id);
i++;
}
} else {
// If it is on a wall NSEW
FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
FlatLocation endLocation = startLocation.clone().add(poster.getColumnCount(), poster.getRowCount());
if (player.getGameMode() == GameMode.CREATIVE)
PosterWall.expand(startLocation,startFrame.getAttachedFace(), poster.getColumnCount(), poster.getRowCount());
wall.loc1 = startLocation;
wall.loc2 = endLocation;
@ -298,10 +291,11 @@ abstract public class SplatterMapManager {
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
if (i == 0) {//First map need to be rotate one time Clockwise
frame.setRotation(Rotation.NONE.rotateCounterClockwise());
} else {
frame.setRotation(Rotation.NONE);
}
else{frame.setRotation(Rotation.NONE);}
MapInitEvent.initMap(id);
++i;
}
@ -312,10 +306,8 @@ abstract public class SplatterMapManager {
/**
* Remove splattermap
*
* @param startFrame
* Frame clicked by the player
* @param player
* The player removing the map
* @param startFrame Frame clicked by the player
* @param player The player removing the map
* @return
*/
static public PosterMap removeSplatterMap(ItemFrame startFrame, Player player) {
@ -326,13 +318,13 @@ abstract public class SplatterMapManager {
if (!poster.hasColumnData())
return null;
FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
ItemFrame[] matchingFrames=null;
ItemFrame[] matchingFrames = null;
switch(startFrame.getFacing()){
switch (startFrame.getFacing()) {
case UP:
case DOWN:
matchingFrames = PosterOnASurface.getMatchingMapFrames(poster, loc,
MapManager.getMapIdFromItemStack(startFrame.getItem()),WorldUtils.get4thOrientation(player.getLocation()));//startFrame.getFacing());
MapManager.getMapIdFromItemStack(startFrame.getItem()), WorldUtils.get4thOrientation(player.getLocation()));//startFrame.getFacing());
break;
case NORTH: