mirror of
https://github.com/zDevelopers/ImageOnMap.git
synced 2025-02-22 06:11:28 +01:00
ground and ceiling map possible, many bugs left to fix
This commit is contained in:
parent
a8d7a3ab2f
commit
f9c9049aa6
@ -34,4 +34,6 @@ public final class PluginConfiguration extends Configuration
|
||||
|
||||
static public ConfigurationItem<Integer> MAP_GLOBAL_LIMIT = item("map-global-limit", 0, "Limit-map-by-server");
|
||||
static public ConfigurationItem<Integer> MAP_PLAYER_LIMIT = item("map-player-limit", 0, "Limit-map-by-player");
|
||||
|
||||
static public ConfigurationItem<Integer> MAP_SIZE_NOTOP_LIMIT = item("map-size-notop-limit", 0, "Size-limit-map-notop");
|
||||
}
|
||||
|
@ -18,155 +18,167 @@
|
||||
|
||||
package fr.moribus.imageonmap.map;
|
||||
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
|
||||
import fr.zcraft.zlib.tools.PluginLogger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PosterMap extends ImageMap
|
||||
{
|
||||
protected final int[] mapsIDs;
|
||||
protected final int columnCount;
|
||||
protected final int rowCount;
|
||||
|
||||
public PosterMap(UUID userUUID, int[] mapsIDs, String id, String name, int columnCount, int rowCount)
|
||||
{
|
||||
super(userUUID, Type.POSTER, id, name);
|
||||
this.mapsIDs = mapsIDs;
|
||||
this.columnCount = Math.max(columnCount, 0);
|
||||
this.rowCount = Math.max(rowCount, 0);
|
||||
}
|
||||
|
||||
public PosterMap(UUID userUUID, int[] mapsIDs, int columnCount, int rowCount)
|
||||
{
|
||||
this(userUUID, mapsIDs, null, null, columnCount, rowCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getMapsIDs()
|
||||
{
|
||||
return mapsIDs;
|
||||
}
|
||||
public class PosterMap extends ImageMap {
|
||||
protected final int[] mapsIDs;
|
||||
protected final int columnCount;
|
||||
protected final int rowCount;
|
||||
|
||||
@Override
|
||||
public boolean managesMap(int mapID)
|
||||
{
|
||||
for(int i = 0; i < mapsIDs.length; i++)
|
||||
{
|
||||
if(mapsIDs[i] == mapID) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public PosterMap(UUID userUUID, int[] mapsIDs, String id, String name, int columnCount, int rowCount) {
|
||||
super(userUUID, Type.POSTER, id, name);
|
||||
this.mapsIDs = mapsIDs;
|
||||
this.columnCount = Math.max(columnCount, 0);
|
||||
this.rowCount = Math.max(rowCount, 0);
|
||||
}
|
||||
|
||||
/* ====== Serialization methods ====== */
|
||||
|
||||
public PosterMap(Map<String, Object> map, UUID userUUID) throws InvalidConfigurationException
|
||||
{
|
||||
super(map, userUUID, Type.POSTER);
|
||||
|
||||
columnCount = getFieldValue(map, "columns");
|
||||
rowCount = getFieldValue(map, "rows");
|
||||
|
||||
List<Integer> idList = getFieldValue(map, "mapsIDs");
|
||||
mapsIDs = new int[idList.size()];
|
||||
for(int i = 0, c = idList.size(); i < c; i++)
|
||||
{
|
||||
mapsIDs[i] = (int) idList.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postSerialize(Map<String, Object> map)
|
||||
{
|
||||
map.put("columns", columnCount);
|
||||
map.put("rows", rowCount);
|
||||
map.put("mapsIDs", mapsIDs);
|
||||
}
|
||||
|
||||
/* ====== Getters & Setters ====== */
|
||||
|
||||
/**
|
||||
* Returns the amount of columns in the poster map
|
||||
* @return The number of columns, or 0 if this data is missing
|
||||
*/
|
||||
public int getColumnCount()
|
||||
{
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of rows in the poster map
|
||||
* @return The number of rows, or 0 if this data is missing
|
||||
*/
|
||||
public int getRowCount()
|
||||
{
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public int getColumnAt(int i)
|
||||
{
|
||||
if(columnCount == 0) return 0;
|
||||
return (i % columnCount);
|
||||
}
|
||||
|
||||
public int getRowAt(int i)
|
||||
{
|
||||
if(columnCount == 0) return 0;
|
||||
return (i / columnCount);
|
||||
}
|
||||
|
||||
public int getIndexAt(int col, int row)
|
||||
{
|
||||
return columnCount * row + col;
|
||||
}
|
||||
public PosterMap(UUID userUUID, int[] mapsIDs, int columnCount, int rowCount) {
|
||||
this(userUUID, mapsIDs, null, null, columnCount, rowCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map id at the given column and line.
|
||||
*
|
||||
* @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 int getMapIdAt(int x, int y)
|
||||
{
|
||||
return mapsIDs[y * columnCount + x];
|
||||
}
|
||||
|
||||
public int getMapIdAtReverseY(int index)
|
||||
{
|
||||
int x = index % (columnCount);
|
||||
int y = index / (columnCount);
|
||||
return getMapIdAt(x, rowCount - y - 1);
|
||||
}
|
||||
|
||||
public int getMapIdAt(int index)
|
||||
{
|
||||
return mapsIDs[index];
|
||||
}
|
||||
|
||||
public boolean hasColumnData()
|
||||
{
|
||||
return rowCount != 0 && columnCount != 0;
|
||||
}
|
||||
@Override
|
||||
public int[] getMapsIDs() {
|
||||
return mapsIDs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMapCount()
|
||||
{
|
||||
return mapsIDs.length;
|
||||
}
|
||||
|
||||
public int getIndex(int mapID)
|
||||
{
|
||||
for(int i = 0; i < mapsIDs.length; i++)
|
||||
{
|
||||
if(mapsIDs[i] == mapID) return i;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Invalid map ID");
|
||||
}
|
||||
@Override
|
||||
public boolean managesMap(int mapID) {
|
||||
for (int i = 0; i < mapsIDs.length; i++) {
|
||||
if (mapsIDs[i] == mapID)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ====== Serialization methods ====== */
|
||||
|
||||
public PosterMap(Map<String, Object> map, UUID userUUID) throws InvalidConfigurationException {
|
||||
super(map, userUUID, Type.POSTER);
|
||||
|
||||
columnCount = getFieldValue(map, "columns");
|
||||
rowCount = getFieldValue(map, "rows");
|
||||
|
||||
List<Integer> idList = getFieldValue(map, "mapsIDs");
|
||||
mapsIDs = new int[idList.size()];
|
||||
for (int i = 0, c = idList.size(); i < c; i++) {
|
||||
mapsIDs[i] = idList.get(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postSerialize(Map<String, Object> map) {
|
||||
map.put("columns", columnCount);
|
||||
map.put("rows", rowCount);
|
||||
map.put("mapsIDs", mapsIDs);
|
||||
}
|
||||
|
||||
/* ====== Getters & Setters ====== */
|
||||
|
||||
/**
|
||||
* Returns the amount of columns in the poster map
|
||||
*
|
||||
* @return The number of columns, or 0 if this data is missing
|
||||
*/
|
||||
public int getColumnCount() {
|
||||
return columnCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of rows in the poster map
|
||||
*
|
||||
* @return The number of rows, or 0 if this data is missing
|
||||
*/
|
||||
public int getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public int getColumnAt(int i) {
|
||||
if (columnCount == 0)
|
||||
return 0;
|
||||
return (i % columnCount);
|
||||
}
|
||||
|
||||
public int getRowAt(int i) {
|
||||
if (columnCount == 0)
|
||||
return 0;
|
||||
return (i / columnCount);
|
||||
}
|
||||
|
||||
public int getIndexAt(int col, int row) {
|
||||
return columnCount * row + col;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the map id at the given column and line.
|
||||
*
|
||||
* @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 int getMapIdAt(int x, int y) {
|
||||
return mapsIDs[y * columnCount + x];
|
||||
}
|
||||
|
||||
public int getMapIdAtReverseY(int index) {
|
||||
int x = index % (columnCount);
|
||||
int y = index / (columnCount);
|
||||
return getMapIdAt(x, rowCount - y - 1);
|
||||
}
|
||||
|
||||
public int getMapIdAtReverseZ(int index, BlockFace orientation, BlockFace bf) {
|
||||
int x = 0, y = 0;
|
||||
switch (bf) {
|
||||
case UP:
|
||||
|
||||
x = index % (columnCount);
|
||||
y = index / (columnCount);
|
||||
|
||||
break;
|
||||
case DOWN:
|
||||
|
||||
x = (columnCount - 1) - index % (columnCount);
|
||||
y = index / (columnCount);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return getMapIdAt(x, rowCount - y - 1);
|
||||
|
||||
}
|
||||
|
||||
public int getMapIdAt(int index) {
|
||||
return mapsIDs[index];
|
||||
}
|
||||
|
||||
public boolean hasColumnData() {
|
||||
return rowCount != 0 && columnCount != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMapCount() {
|
||||
return mapsIDs.length;
|
||||
}
|
||||
|
||||
public int getIndex(int mapID) {
|
||||
for (int i = 0; i < mapsIDs.length; i++) {
|
||||
if (mapsIDs[i] == mapID)
|
||||
return i;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Invalid map ID");
|
||||
}
|
||||
|
||||
}
|
||||
|
172
src/main/java/fr/moribus/imageonmap/ui/PosterOnASurface.java
Normal file
172
src/main/java/fr/moribus/imageonmap/ui/PosterOnASurface.java
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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.PosterMap;
|
||||
import fr.zcraft.zlib.tools.PluginLogger;
|
||||
import fr.zcraft.zlib.tools.world.FlatLocation;
|
||||
import fr.zcraft.zlib.tools.world.WorldUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PosterOnASurface {
|
||||
|
||||
public FlatLocation loc1;
|
||||
public FlatLocation loc2;
|
||||
|
||||
public ItemFrame[] frames;
|
||||
|
||||
public boolean isValid(Player p) {
|
||||
ItemFrame curFrame;
|
||||
PluginLogger.info("Test");
|
||||
|
||||
FlatLocation l = loc1.clone();
|
||||
|
||||
BlockFace bf = WorldUtils.get4thOrientation(p.getLocation());
|
||||
|
||||
l.subtract(loc2);
|
||||
;
|
||||
|
||||
int distX = Math.abs(l.getBlockX());
|
||||
int distZ = Math.abs(l.getBlockZ());
|
||||
PluginLogger.info("dist X " + distX);
|
||||
PluginLogger.info("dist Z " + distZ);
|
||||
frames = new ItemFrame[distX * distZ];
|
||||
l = loc1.clone();
|
||||
for (int x = 0; x < distX; x++) {
|
||||
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());
|
||||
|
||||
if (curFrame == null)
|
||||
return false;
|
||||
PluginLogger.info("x " + x + " | z " + z);
|
||||
frames[z * distX + x] = curFrame;
|
||||
PluginLogger.info("ind frame " + z * distX + x);
|
||||
|
||||
switch (bf) {
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
l.addH(0, 1, bf);
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
l.addH(-1, 0, bf);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
switch (bf) {
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
l.addH(1, -distZ, bf);
|
||||
break;
|
||||
case EAST:
|
||||
case WEST:
|
||||
l.addH(distX, -1, bf);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void expand() {
|
||||
|
||||
}
|
||||
|
||||
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId, BlockFace bf) {
|
||||
int mapIndex = map.getIndex(mapId);
|
||||
int x = map.getColumnAt(mapIndex), y = map.getRowAt(mapIndex);
|
||||
|
||||
return getMatchingMapFrames(map, location.clone().addH(-x, y,bf),bf);
|
||||
}
|
||||
|
||||
static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, BlockFace bf) {
|
||||
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) {
|
||||
int mapIndex = map.getIndexAt(x, y);
|
||||
ItemFrame frame = getMapFrameAt(loc, map);
|
||||
if (frame != null)
|
||||
frames[mapIndex] = frame;
|
||||
loc.add(1, 0);
|
||||
}
|
||||
loc.setX(location.getX());
|
||||
loc.setZ(location.getZ());
|
||||
loc.addH(0, -1,bf);
|
||||
}
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
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;
|
||||
ItemFrame frame = (ItemFrame) entity;
|
||||
if (frame.getFacing() != location.getFacing())
|
||||
continue;
|
||||
ItemStack item = frame.getItem();
|
||||
if (item.getType() != Material.FILLED_MAP)
|
||||
continue;
|
||||
if (!map.managesMap(item))
|
||||
continue;
|
||||
return frame;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
ItemFrame frame = (ItemFrame) entity;
|
||||
if (frame.getFacing() != facing)
|
||||
continue;
|
||||
ItemStack item = frame.getItem();
|
||||
if (item.getType() != Material.AIR)
|
||||
continue;
|
||||
return frame;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
package fr.moribus.imageonmap.ui;
|
||||
|
||||
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.WorldUtils;
|
||||
import org.bukkit.Location;
|
||||
@ -45,6 +46,8 @@ public class PosterWall
|
||||
int distX = FlatLocation.flatBlockDistanceX(loc1, loc2);
|
||||
int distY = FlatLocation.flatBlockDistanceY(loc1, loc2);
|
||||
|
||||
PluginLogger.info("dist X "+distX);
|
||||
PluginLogger.info("dist Y "+distY);
|
||||
frames = new ItemFrame[distX * distY];
|
||||
|
||||
for(int x = 0; x < distX; x++)
|
||||
|
@ -33,182 +33,269 @@ import fr.zcraft.zlib.tools.items.ItemStackBuilder;
|
||||
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.block.BlockFace;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.MapMeta;
|
||||
|
||||
abstract public class SplatterMapManager
|
||||
{
|
||||
private 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, " - ")
|
||||
.title(ChatColor.GRAY, I.t("{0} × {1}", map.getColumnCount(), map.getRowCount()))
|
||||
.loreLine(ChatColor.GRAY, map.getId())
|
||||
.loreLine()
|
||||
/// Title in a splatter map tooltip
|
||||
.loreLine(ChatColor.BLUE, I.t("Item frames needed"))
|
||||
/// Size of a map stored in a splatter map
|
||||
.loreLine(ChatColor.GRAY, I.t("{0} × {1} (total {2} frames)", map.getColumnCount(), map.getRowCount(), map.getColumnCount() * map.getRowCount()))
|
||||
.loreLine()
|
||||
/// Title in a splatter map tooltip
|
||||
.loreLine(ChatColor.BLUE, I.t("How to use this?"))
|
||||
.longLore(ChatColor.GRAY + I.t("Place empty item frames on a wall, enough to host the whole map. Then, right-click on the bottom-left frame with this map."), 40)
|
||||
.loreLine()
|
||||
.longLore(ChatColor.GRAY + I.t("Shift-click one of the placed maps to remove the whole poster in one shot."), 40)
|
||||
.hideAttributes()
|
||||
.craftItem();
|
||||
abstract public class SplatterMapManager {
|
||||
private SplatterMapManager() {
|
||||
}
|
||||
|
||||
final MapMeta meta = (MapMeta) splatter.getItemMeta();
|
||||
meta.setMapId(map.getMapIdAt(0));
|
||||
meta.setColor(Color.GREEN);
|
||||
splatter.setItemMeta(meta);
|
||||
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, " - ")
|
||||
.title(ChatColor.GRAY, I.t("{0} × {1}", map.getColumnCount(), map.getRowCount()))
|
||||
.loreLine(ChatColor.GRAY, map.getId()).loreLine()
|
||||
/// Title in a splatter map tooltip
|
||||
.loreLine(ChatColor.BLUE, I.t("Item frames needed"))
|
||||
/// Size of a map stored in a splatter map
|
||||
.loreLine(ChatColor.GRAY,
|
||||
I.t("{0} × {1} (total {2} frames)", map.getColumnCount(), map.getRowCount(),
|
||||
map.getColumnCount() * map.getRowCount()))
|
||||
.loreLine()
|
||||
/// Title in a splatter map tooltip
|
||||
.loreLine(ChatColor.BLUE, I.t("How to use this?"))
|
||||
.longLore(
|
||||
ChatColor.GRAY
|
||||
+ I.t("Place empty item frames on a wall, enough to host the whole map. Then, right-click on the bottom-left frame with this map."),
|
||||
40)
|
||||
.loreLine()
|
||||
.longLore(ChatColor.GRAY
|
||||
+ I.t("Shift-click one of the placed maps to remove the whole poster in one shot."), 40)
|
||||
.hideAttributes().craftItem();
|
||||
|
||||
return addSplatterAttribute(splatter);
|
||||
}
|
||||
final MapMeta meta = (MapMeta) splatter.getItemMeta();
|
||||
meta.setMapId(map.getMapIdAt(0));
|
||||
meta.setColor(Color.GREEN);
|
||||
splatter.setItemMeta(meta);
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* @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.
|
||||
*/
|
||||
static public ItemStack addSplatterAttribute(final ItemStack itemStack)
|
||||
{
|
||||
try
|
||||
{
|
||||
final NBTCompound nbt = NBT.fromItemStack(itemStack);
|
||||
final NBTList enchantments = new NBTList();
|
||||
final NBTCompound protection = new NBTCompound();
|
||||
return addSplatterAttribute(splatter);
|
||||
}
|
||||
|
||||
protection.put("id", "minecraft:mending");
|
||||
protection.put("lvl", 1);
|
||||
enchantments.add(protection);
|
||||
/**
|
||||
* 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).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* @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.
|
||||
*/
|
||||
static public ItemStack addSplatterAttribute(final ItemStack itemStack) {
|
||||
try {
|
||||
final NBTCompound nbt = NBT.fromItemStack(itemStack);
|
||||
final NBTList enchantments = new NBTList();
|
||||
final NBTCompound protection = new NBTCompound();
|
||||
|
||||
nbt.put("Enchantments", enchantments);
|
||||
protection.put("id", "minecraft:mending");
|
||||
protection.put("lvl", 1);
|
||||
enchantments.add(protection);
|
||||
|
||||
return NBT.addToItemStack(itemStack, nbt, false);
|
||||
}
|
||||
catch (NBTException | NMSException e)
|
||||
{
|
||||
PluginLogger.error("Unable to set Splatter Map attribute on item", e);
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
nbt.put("Enchantments", enchantments);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return True if the attribute was detected.
|
||||
*/
|
||||
static public boolean hasSplatterAttributes(ItemStack itemStack)
|
||||
{
|
||||
try
|
||||
{
|
||||
final NBTCompound nbt = NBT.fromItemStack(itemStack);
|
||||
if (!nbt.containsKey("Enchantments")) return false;
|
||||
return NBT.addToItemStack(itemStack, nbt, false);
|
||||
} catch (NBTException | NMSException e) {
|
||||
PluginLogger.error("Unable to set Splatter Map attribute on item", e);
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
|
||||
final Object enchantments = nbt.get("Enchantments");
|
||||
if (!(enchantments instanceof NBTList)) return false;
|
||||
/**
|
||||
* 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.
|
||||
* @return True if the attribute was detected.
|
||||
*/
|
||||
static public boolean hasSplatterAttributes(ItemStack itemStack) {
|
||||
try {
|
||||
final NBTCompound nbt = NBT.fromItemStack(itemStack);
|
||||
if (!nbt.containsKey("Enchantments"))
|
||||
return false;
|
||||
|
||||
return !((NBTList) enchantments).isEmpty();
|
||||
}
|
||||
catch (NMSException e)
|
||||
{
|
||||
PluginLogger.error("Unable to get Splatter Map attribute on item", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static public boolean isSplatterMap(ItemStack itemStack)
|
||||
{
|
||||
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.getInventory().getItemInMainHand());
|
||||
final Object enchantments = nbt.get("Enchantments");
|
||||
if (!(enchantments instanceof NBTList))
|
||||
return false;
|
||||
|
||||
if(!(map instanceof PosterMap)) return false;
|
||||
PosterMap poster = (PosterMap) map;
|
||||
return !((NBTList) enchantments).isEmpty();
|
||||
} catch (NMSException e) {
|
||||
PluginLogger.error("Unable to get Splatter Map attribute on item", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
|
||||
FlatLocation endLocation = startLocation.clone().add(poster.getColumnCount(), poster.getRowCount());
|
||||
PosterWall wall = new PosterWall();
|
||||
|
||||
wall.loc1 = startLocation;
|
||||
wall.loc2 = endLocation;
|
||||
|
||||
if (!wall.isValid())
|
||||
{
|
||||
MessageSender.sendActionBarMessage(player, I.t("{ce}There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(), poster.getRowCount()));
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (ItemFrame frame : wall.frames)
|
||||
{
|
||||
int id = poster.getMapIdAtReverseY(i);
|
||||
frame.setItem(new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem());
|
||||
MapInitEvent.initMap(id);
|
||||
++i;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static public PosterMap removeSplatterMap(ItemFrame startFrame)
|
||||
{
|
||||
final ImageMap map = MapManager.getMap(startFrame.getItem());
|
||||
if(!(map instanceof PosterMap)) return null;
|
||||
PosterMap poster = (PosterMap) map;
|
||||
if(!poster.hasColumnData()) return null;
|
||||
FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
|
||||
ItemFrame[] matchingFrames = PosterWall.getMatchingMapFrames(poster, loc, MapManager.getMapIdFromItemStack(startFrame.getItem()));
|
||||
if(matchingFrames == null) return null;
|
||||
|
||||
for(ItemFrame frame : matchingFrames)
|
||||
{
|
||||
if(frame != null) frame.setItem(null);
|
||||
}
|
||||
|
||||
return poster;
|
||||
}
|
||||
static public boolean isSplatterMap(ItemStack itemStack) {
|
||||
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.getInventory().getItemInMainHand());
|
||||
|
||||
if (!(map instanceof PosterMap))
|
||||
return false;
|
||||
PosterMap poster = (PosterMap) map;
|
||||
PosterWall wall = new PosterWall();
|
||||
// NEW
|
||||
if (startFrame.getFacing().equals(BlockFace.DOWN) || startFrame.getFacing().equals(BlockFace.UP)) {
|
||||
PluginLogger.info("UP or DOWN ");
|
||||
|
||||
PosterOnASurface surface = new PosterOnASurface();
|
||||
FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
|
||||
FlatLocation endLocation = startLocation.clone().addH(poster.getColumnCount(), poster.getRowCount(),
|
||||
WorldUtils.get4thOrientation(player.getLocation()));
|
||||
PluginLogger.info("Before loc asign ");
|
||||
surface.loc1 = startLocation;
|
||||
surface.loc2 = endLocation;
|
||||
PluginLogger.info("After loc asign ");
|
||||
|
||||
// todo impletation
|
||||
if (!surface.isValid(player)) {
|
||||
MessageSender.sendActionBarMessage(player,
|
||||
I.t("{ce}There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(),
|
||||
poster.getRowCount()));
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (ItemFrame frame : surface.frames) {
|
||||
PluginLogger.info("Test " + frame.getName());
|
||||
BlockFace bf = WorldUtils.get4thOrientation(player.getLocation());
|
||||
int id = poster.getMapIdAtReverseZ(i, bf, startFrame.getFacing());
|
||||
|
||||
Rotation rot = frame.getRotation();
|
||||
|
||||
// NESW
|
||||
//PluginLogger.info("ordinal " + rot.ordinal() );
|
||||
/*switch(bf){
|
||||
case NORTH:
|
||||
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) {
|
||||
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());
|
||||
MapInitEvent.initMap(id);
|
||||
++i;
|
||||
}
|
||||
} else {
|
||||
FlatLocation startLocation = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
|
||||
FlatLocation endLocation = startLocation.clone().add(poster.getColumnCount(), poster.getRowCount());
|
||||
|
||||
wall.loc1 = startLocation;
|
||||
wall.loc2 = endLocation;
|
||||
PluginLogger.info("startLocation " + startLocation + " | endLocation " + endLocation);
|
||||
if (!wall.isValid()) {
|
||||
MessageSender.sendActionBarMessage(player,
|
||||
I.t("{ce}There is not enough space to place this map ({0} × {1}).", poster.getColumnCount(),
|
||||
poster.getRowCount()));
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (ItemFrame frame : wall.frames) {
|
||||
int id = poster.getMapIdAtReverseY(i);
|
||||
frame.setItem(new ItemStackBuilder(Material.FILLED_MAP).nbt(ImmutableMap.of("map", id)).craftItem());
|
||||
MapInitEvent.initMap(id);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static public PosterMap removeSplatterMap(ItemFrame startFrame) {
|
||||
final ImageMap map = MapManager.getMap(startFrame.getItem());
|
||||
if (!(map instanceof PosterMap))
|
||||
return null;
|
||||
PosterMap poster = (PosterMap) map;
|
||||
if (!poster.hasColumnData())
|
||||
return null;
|
||||
FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
|
||||
ItemFrame[] matchingFrames=null;
|
||||
switch(startFrame.getFacing()){
|
||||
case UP:
|
||||
case DOWN:
|
||||
matchingFrames = PosterOnASurface.getMatchingMapFrames(poster, loc,
|
||||
MapManager.getMapIdFromItemStack(startFrame.getItem()),startFrame.getFacing());
|
||||
break;
|
||||
case NORTH:
|
||||
case SOUTH:
|
||||
case EAST:
|
||||
case WEST:
|
||||
matchingFrames = PosterWall.getMatchingMapFrames(poster, loc,
|
||||
MapManager.getMapIdFromItemStack(startFrame.getItem()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (matchingFrames == null)
|
||||
return null;
|
||||
|
||||
for (ItemFrame frame : matchingFrames) {
|
||||
if (frame != null)
|
||||
frame.setItem(null);
|
||||
}
|
||||
|
||||
return poster;
|
||||
}
|
||||
}
|
||||
|
@ -16,3 +16,7 @@ collect-data: true
|
||||
# 0 means unlimited.
|
||||
map-global-limit: 0
|
||||
map-player-limit: 0
|
||||
|
||||
#Limit to the size of map non operator can render
|
||||
#The value is the number of map used for the image for instance if you make a map 10 X 12 you will get 120 maps
|
||||
map-size-notop-limit: 256
|
Loading…
Reference in New Issue
Block a user