cache = mapItemCache.get(player.getUniqueId());
- if (cache == null)
- {
+ if (cache == null) {
cache = new ArrayDeque<>();
mapItemCache.put(player.getUniqueId(), cache);
}
return cache;
}
- static private String getMapTitle(ItemStack item)
- {
- ImageMap map = MapManager.getMap(item);
- if (map instanceof SingleMap)
- {
- return map.getName();
- }
- else
- {
- PosterMap poster = (PosterMap) map;
- int index = poster.getIndex(MapManager.getMapIdFromItemStack(item));
- if (poster.hasColumnData())
- return getMapTitle(poster, poster.getRowAt(index), poster.getColumnAt(index));
-
- return getMapTitle(poster, index);
- }
- }
-
- static private void onItemFramePlace(ItemFrame frame, Player player, PlayerInteractEntityEvent event)
- {
+ private static void onItemFramePlace(ItemFrame frame, Player player, PlayerInteractEntityEvent event) {
final ItemStack mapItem = player.getInventory().getItemInMainHand();
- if (frame.getItem().getType() != Material.AIR) return;
- if (!MapManager.managesMap(mapItem)) return;
+ if (frame.getItem().getType() != Material.AIR) {
+ return;
+ }
+ if (!MapManager.managesMap(mapItem)) {
+ return;
+ }
- if (SplatterMapManager.hasSplatterAttributes(mapItem))
- {
- if (!SplatterMapManager.placeSplatterMap(frame, player,event)){
+ if (SplatterMapManager.hasSplatterAttributes(mapItem)) {
+ if (!SplatterMapManager.placeSplatterMap(frame, player, event)) {
event.setCancelled(true); //In case of an error allow to cancel map placement
return;
}
- if(frame.getFacing()!= BlockFace.UP&&frame.getFacing()!= BlockFace.DOWN)
+ if (frame.getFacing() != BlockFace.UP && frame.getFacing() != BlockFace.DOWN) {
frame.setRotation(Rotation.NONE.rotateCounterClockwise());
- }
- else
- {
- if(frame.getFacing()!= BlockFace.UP&&frame.getFacing()!= BlockFace.DOWN)
+ }
+ } else {
+ if (frame.getFacing() != BlockFace.UP && frame.getFacing() != BlockFace.DOWN) {
frame.setRotation(Rotation.NONE.rotateCounterClockwise());
+ }
// If the item has a display name, bot not one from an anvil by the player, we remove it
// If it is not displayed on hover on the wall.
- if (mapItem.hasItemMeta() && mapItem.getItemMeta().hasDisplayName() && mapItem.getItemMeta().getDisplayName().startsWith("§6"))
- {
+ if (mapItem.hasItemMeta() && mapItem.getItemMeta().hasDisplayName()
+ && mapItem.getItemMeta().getDisplayName().startsWith("§6")) {
final ItemStack frameItem = mapItem.clone();
final ItemMeta meta = frameItem.getItemMeta();
@@ -289,9 +274,7 @@ public class MapItemManager implements Listener
frameItem.setItemMeta(meta);
frame.setItem(frameItem);
- }
-
- else{
+ } else {
frame.setItem(mapItem);
}
@@ -301,29 +284,31 @@ public class MapItemManager implements Listener
ItemUtils.consumeItem(player);
}
- static private void onItemFrameRemove(ItemFrame frame, Player player, EntityDamageByEntityEvent event)
- {
+ private static void onItemFrameRemove(ItemFrame frame, Player player, EntityDamageByEntityEvent event) {
ItemStack item = frame.getItem();
- if (frame.getItem().getType() != Material.FILLED_MAP) return;
+ if (item.getType() != Material.FILLED_MAP) {
+ return;
+ }
- if (Permissions.REMOVE_SPLATTER_MAP.grantedTo(player))
- {
- if (player.isSneaking())
- {
- PosterMap poster = SplatterMapManager.removeSplatterMap(frame,player);
- if (poster != null)
- {
+ if (Permissions.REMOVE_SPLATTER_MAP.grantedTo(player)) {
+ if (player.isSneaking()) {
+ PosterMap poster = SplatterMapManager.removeSplatterMap(frame, player);
+ if (poster != null) {
event.setCancelled(true);
- if (player.getGameMode() != GameMode.CREATIVE || !SplatterMapManager.hasSplatterMap(player, poster))
+ if (player.getGameMode() != GameMode.CREATIVE
+ || !SplatterMapManager.hasSplatterMap(player, poster)) {
poster.give(player);
+ }
return;
}
}
}
- if (!MapManager.managesMap(frame.getItem())) return;
+ if (!MapManager.managesMap(frame.getItem())) {
+ return;
+ }
frame.setItem(new ItemStackBuilder(item)
.title(getMapTitle(item))
@@ -333,18 +318,22 @@ public class MapItemManager implements Listener
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- static public void onEntityDamage(EntityDamageByEntityEvent event)
- {
- if (!(event.getEntity() instanceof ItemFrame)) return;
- if (!(event.getDamager() instanceof Player)) return;
+ public static void onEntityDamage(EntityDamageByEntityEvent event) {
+ if (!(event.getEntity() instanceof ItemFrame)) {
+ return;
+ }
+ if (!(event.getDamager() instanceof Player)) {
+ return;
+ }
onItemFrameRemove((ItemFrame) event.getEntity(), (Player) event.getDamager(), event);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- static public void onEntityInteract(PlayerInteractEntityEvent event)
- {
- if (!(event.getRightClicked() instanceof ItemFrame)) return;
+ public static void onEntityInteract(PlayerInteractEntityEvent event) {
+ if (!(event.getRightClicked() instanceof ItemFrame)) {
+ return;
+ }
onItemFramePlace((ItemFrame) event.getRightClicked(), event.getPlayer(), event);
}
}
diff --git a/src/main/java/fr/moribus/imageonmap/ui/PosterOnASurface.java b/src/main/java/fr/moribus/imageonmap/ui/PosterOnASurface.java
index f0eda45..35f90a6 100644
--- a/src/main/java/fr/moribus/imageonmap/ui/PosterOnASurface.java
+++ b/src/main/java/fr/moribus/imageonmap/ui/PosterOnASurface.java
@@ -49,188 +49,211 @@ import org.bukkit.inventory.ItemStack;
public class PosterOnASurface {
- public FlatLocation loc1;
- public FlatLocation loc2;
+ public FlatLocation loc1;
+ public FlatLocation loc2;
- public ItemFrame[] frames;
+ public ItemFrame[] frames;
- public boolean isValid(Player p) {
- ItemFrame curFrame;
+ /**
+ * Return the list of map Frames associated with a specific map
+ */
+ public static ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId, BlockFace bf) {
+ int mapIndex = map.getIndex(mapId);
+ //int x = map.getColumnAt(mapIndex), y = map.getRowAt(mapIndex);
+ int x = 0;
+ int y = 0;
+ switch (bf) {
+ case EAST:
+ case WEST:
+ y = map.getColumnCount() - 1;
+ break;
+ case NORTH:
+ case SOUTH:
+ y = map.getRowCount() - 1;
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + bf);
+ }
+ return getMatchingMapFrames(map, location.clone().addH(x, y, bf), bf).clone();
+ }
+
+ public static ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, BlockFace bf) {
+ ItemFrame[] frames = new ItemFrame[map.getMapCount()];
+ FlatLocation loc = location.clone();
- FlatLocation l = loc1.clone();
+ int x = 0;
+ int y = 0;
+ switch (bf) {
+ case EAST:
+ case WEST:
+ //X=map.getRowCount();
+ //Y=map.getColumnCount();
+ //break;
+ case NORTH:
+ case SOUTH:
- BlockFace bf = WorldUtils.get4thOrientation(p.getLocation());
+ y = map.getRowCount();
+ x = map.getColumnCount();
+ break;
- l.subtract(loc2);
+ default:
+ throw new IllegalStateException("Unexpected value: " + bf);
+ }
+
+ for (int j = 0; j < y; ++j) {
+ for (int i = 0; i < x; ++i) {
+ int mapIndex = map.getIndexAt(i, j);
+
+ ItemFrame frame = getMapFrameAt(loc, map);
+ if (frame != null) {
+ frames[mapIndex] = frame;
+ }
+ switch (bf) {
+ case EAST:
+ case WEST:
+ loc.addH(0, -1, bf);
+ break;
+ case NORTH:
+ case SOUTH:
+ loc.addH(1, 0, bf);
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + bf);
+ }
- int distX = Math.abs(l.getBlockX());
- int distZ = Math.abs(l.getBlockZ());
+ }
- frames = new ItemFrame[distX * distZ];
- l = loc1.clone();
- for (int x = 0; x < distX; x++) {
- for (int z = 0; z < distZ; z++) {
+ switch (bf) {
+ case EAST:
+ case WEST:
+ loc.addH(1, map.getColumnCount(), bf);//test
- curFrame = getEmptyFrameAt(l, l.getFacing());
+ break;
+ case NORTH:
+ case SOUTH:
+ loc.addH(-map.getColumnCount(), -1, bf);
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + bf);
+ }
- if (curFrame == null)
- return false;
+ }
- frames[z * distX + x] = curFrame;
+ return frames;
+ }
- switch (bf) {
- case NORTH:
- case SOUTH:
- l.addH(0, 1, bf);
- break;
- case EAST:
- case WEST:
- l.addH(1, 0, bf);
- break;
- }
+ public static 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;
+ }
- switch (bf) {
- case NORTH:
- case SOUTH:
- l.addH(1, -distZ, bf);
- break;
- case EAST:
- case WEST:
- l.addH(-distZ, 1, bf);
- break;
- }
- }
- return true;
- }
+ return null;
+ }
- public void expand() {
+ public static 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 the list of map Frames associated with a specific map
- * */
- 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);
- int x=0,y=0;
- switch(bf){
- case EAST:
- case WEST:
- y=map.getColumnCount()-1;
- break;
- case NORTH:
- case SOUTH:
- y=map.getRowCount()-1;
- break;
- }
- return getMatchingMapFrames(map, location.clone().addH(x, y,bf),bf).clone();
- }
+ return null;
+ }
- static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, BlockFace bf) {
- ItemFrame[] frames = new ItemFrame[map.getMapCount()];
- FlatLocation loc = location.clone();
+ public boolean isValid(Player p) {
+ ItemFrame curFrame;
+ FlatLocation l = loc1.clone();
- int X=0;
- int Y=0;
- switch (bf){
- case EAST:
- case WEST:
- /*X=map.getRowCount();
- Y=map.getColumnCount();
- break;*/
- case NORTH:
- case SOUTH:
+ BlockFace bf = WorldUtils.get4thOrientation(p.getLocation());
- Y=map.getRowCount();
- X=map.getColumnCount();
- break;
-
- }
-
- for (int y = 0; y < Y; ++y) {
- for (int x = 0; x < X; ++x) {
- int mapIndex = map.getIndexAt(x, y);
-
- ItemFrame frame = getMapFrameAt(loc, map);
- if (frame != null)
- frames[mapIndex] = frame;
- switch (bf){
- case EAST:
- case WEST:
- loc.addH( 0,-1,bf);
- break;
- case NORTH:
- case SOUTH:
- loc.addH( 1,0,bf);
- break;
- }
+ l.subtract(loc2);
- }
+ int distX = Math.abs(l.getBlockX());
+ int distZ = Math.abs(l.getBlockZ());
- switch (bf){
- case EAST:
- case WEST:
- loc.addH( 1,map.getColumnCount(),bf);//test
+ frames = new ItemFrame[distX * distZ];
+ l = loc1.clone();
+ for (int x = 0; x < distX; x++) {
+ for (int z = 0; z < distZ; z++) {
- break;
- case NORTH:
- case SOUTH:
- loc.addH(-map.getColumnCount(), -1,bf);
- break;
- }
+ curFrame = getEmptyFrameAt(l, l.getFacing());
- }
+ if (curFrame == null) {
+ return false;
+ }
- return frames;
- }
+ frames[z * distX + x] = curFrame;
- static public ItemFrame getMapFrameAt(FlatLocation location, PosterMap map) {
- Entity entities[] = location.getChunk().getEntities();
+ switch (bf) {
+ case NORTH:
+ case SOUTH:
+ l.addH(0, 1, bf);
+ break;
+ case EAST:
+ case WEST:
+ l.addH(1, 0, bf);
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + bf);
+ }
- 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;
- }
+ switch (bf) {
+ case NORTH:
+ case SOUTH:
+ l.addH(1, -distZ, bf);
+ break;
+ case EAST:
+ case WEST:
+ l.addH(-distZ, 1, bf);
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + bf);
+ }
+ }
+ return true;
+ }
- static public ItemFrame getEmptyFrameAt(Location location, BlockFace facing) {
- Entity entities[] = location.getChunk().getEntities();
+ public void expand() {
- 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;
- }
+ }
}
diff --git a/src/main/java/fr/moribus/imageonmap/ui/PosterWall.java b/src/main/java/fr/moribus/imageonmap/ui/PosterWall.java
index 3f1a062..4bef49d 100644
--- a/src/main/java/fr/moribus/imageonmap/ui/PosterWall.java
+++ b/src/main/java/fr/moribus/imageonmap/ui/PosterWall.java
@@ -46,110 +46,120 @@ import org.bukkit.entity.Entity;
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);
- }
- loc.add(1, 0);
- loc.setY(bottomLeft.getY());
- }
-
- return true;
- }
-
- public void expand()
- {
-
- }
-
- static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId)
- {
+ public static ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location, int mapId) {
int mapIndex = map.getIndex(mapId);
- int x = map.getColumnAt(mapIndex), y = map.getRowAt(mapIndex);
-
+ int x = map.getColumnAt(mapIndex);
+ int y = map.getRowAt(mapIndex);
+
return getMatchingMapFrames(map, location.clone().add(-x, y));
}
-
- static public ItemFrame[] getMatchingMapFrames(PosterMap map, FlatLocation location)
- {
+
+ public static 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());
loc.setZ(location.getZ());
loc.add(0, -1);
}
-
+
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;
+
+ public static 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;
+ 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)
- {
- Entity entities[] = location.getChunk().getEntities();
-
- for(Entity entity : entities)
- {
- if(!(entity instanceof ItemFrame)) continue;
- if(!WorldUtils.blockEquals(location, entity.getLocation())) continue;
+
+ public static 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;
+ 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;
+ }
+
+ public void expand() {
+
+ }
}
diff --git a/src/main/java/fr/moribus/imageonmap/ui/SplatterMapManager.java b/src/main/java/fr/moribus/imageonmap/ui/SplatterMapManager.java
index f740184..a4f3cad 100644
--- a/src/main/java/fr/moribus/imageonmap/ui/SplatterMapManager.java
+++ b/src/main/java/fr/moribus/imageonmap/ui/SplatterMapManager.java
@@ -65,11 +65,11 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.MapMeta;
-abstract public class SplatterMapManager {
+public abstract class SplatterMapManager {
private SplatterMapManager() {
}
- static public ItemStack makeSplatterMap(PosterMap map) {
+ public static ItemStack makeSplatterMap(PosterMap map) {
final ItemStack splatter = new ItemStackBuilder(Material.FILLED_MAP).title(ChatColor.GOLD, map.getName())
@@ -89,7 +89,8 @@ abstract public class SplatterMapManager {
.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."),
+ 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
@@ -108,22 +109,23 @@ 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).
+ *
*
* 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.
+ * @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) {
+ public static ItemStack addSplatterAttribute(final ItemStack itemStack) {
try {
final NBTCompound nbt = NBT.fromItemStack(itemStack);
final NBTList enchantments = new NBTList();
@@ -149,16 +151,16 @@ abstract public class SplatterMapManager {
* @param itemStack The item to check.
* @return True if the attribute was detected.
*/
- static public boolean hasSplatterAttributes(ItemStack itemStack) {
+ public static boolean hasSplatterAttributes(ItemStack itemStack) {
try {
final NBTCompound nbt = NBT.fromItemStack(itemStack);
- if (!nbt.containsKey("Enchantments")) {
- return false;
- }
+ if (!nbt.containsKey("Enchantments")) {
+ return false;
+ }
final Object enchantments = nbt.get("Enchantments");
- if (!(enchantments instanceof NBTList)) {
- return false;
- }
+ if (!(enchantments instanceof NBTList)) {
+ return false;
+ }
return !((NBTList) enchantments).isEmpty();
} catch (NMSException e) {
PluginLogger.error("Unable to get Splatter Map attribute on item", e);
@@ -172,23 +174,23 @@ abstract public class SplatterMapManager {
* @param itemStack The item to check.
* @return True if is a splatter map
*/
- static public boolean isSplatterMap(ItemStack itemStack) {
- if (itemStack == null) {
- return false;
- }
+ public static boolean isSplatterMap(ItemStack itemStack) {
+ if (itemStack == null) {
+ return false;
+ }
return hasSplatterAttributes(itemStack) && MapManager.managesMap(itemStack);
}
//TODO doc a faire
- static public boolean hasSplatterMap(Player player, PosterMap map) {
+ public static 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;
- }
+ if (isSplatterMap(item) && map.managesMap(item)) {
+ return true;
+ }
}
return false;
@@ -201,12 +203,12 @@ abstract public class SplatterMapManager {
* @param player Player placing map
* @return true if the map was correctly placed
*/
- static public boolean placeSplatterMap(ItemFrame startFrame, Player player, PlayerInteractEntityEvent event) {
+ public static boolean placeSplatterMap(ItemFrame startFrame, Player player, PlayerInteractEntityEvent event) {
ImageMap map = MapManager.getMap(player.getInventory().getItemInMainHand());
- if (!(map instanceof PosterMap)) {
- return false;
- }
+ if (!(map instanceof PosterMap)) {
+ return false;
+ }
PosterMap poster = (PosterMap) map;
PosterWall wall = new PosterWall();
@@ -222,7 +224,8 @@ abstract public class SplatterMapManager {
if (!surface.isValid(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()));
@@ -240,10 +243,14 @@ abstract public class SplatterMapManager {
case DOWN:
rot = Rotation.FLIPPED;
break;
+ default:
+ //throw new IllegalStateException("Unexpected value: " + frame.getFacing());
}
- //Rotation management relative to player rotation the default position is North, when on ceiling we flipped the rotation
+ //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
+ if (i == 0) {
+ //First map need to be rotate one time CounterClockwise
rot = rot.rotateCounterClockwise();
}
@@ -270,6 +277,8 @@ abstract public class SplatterMapManager {
rot = rot.rotateCounterClockwise();
frame.setRotation(rot);
break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + bf);
}
@@ -312,16 +321,16 @@ abstract public class SplatterMapManager {
* @param startFrame Frame clicked by the player
* @param player The player removing the map
* @return
- */
- static public PosterMap removeSplatterMap(ItemFrame startFrame, Player player) {
+ **/
+ public static PosterMap removeSplatterMap(ItemFrame startFrame, Player player) {
final ImageMap map = MapManager.getMap(startFrame.getItem());
- if (!(map instanceof PosterMap)) {
- return null;
- }
+ if (!(map instanceof PosterMap)) {
+ return null;
+ }
PosterMap poster = (PosterMap) map;
- if (!poster.hasColumnData()) {
- return null;
- }
+ if (!poster.hasColumnData()) {
+ return null;
+ }
FlatLocation loc = new FlatLocation(startFrame.getLocation(), startFrame.getFacing());
ItemFrame[] matchingFrames = null;
@@ -339,16 +348,19 @@ abstract public class SplatterMapManager {
case WEST:
matchingFrames = PosterWall.getMatchingMapFrames(poster, loc,
MapManager.getMapIdFromItemStack(startFrame.getItem()));
+ break;
+ default:
+ throw new IllegalStateException("Unexpected value: " + startFrame.getFacing());
}
- if (matchingFrames == null) {
- return null;
- }
+ if (matchingFrames == null) {
+ return null;
+ }
for (ItemFrame frame : matchingFrames) {
- if (frame != null) {
- frame.setItem(null);
- }
+ if (frame != null) {
+ frame.setItem(null);
+ }
}
return poster;
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 0f70dee..3c00f16 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -5,103 +5,103 @@ api-version: "1.13"
commands:
- tomap:
- description: render an image in a map
- usage: / [URL]
- maptool:
- description: Manage maps
- maps:
- description: Manage maps through a GUI
- mapgive:
- description: give a map to a player from a player map store, by default take from the player that make the command
- usage: / player_to map_name [player_from]
+ tomap:
+ description: render an image in a map
+ usage: / [URL]
+ maptool:
+ description: Manage maps
+ maps:
+ description: Manage maps through a GUI
+ mapgive:
+ description: give a map to a player from a player map store, by default take from the player that make the command
+ usage: / player_to map_name [player_from]
permissions:
- imageonmap.*:
- description: "Grants all the user permissions (excluding administrative ones)."
- default: true
- children:
- imageonmap.userender: true
- imageonmap.new: true
- imageonmap.list: true
- imageonmap.listother: true
- imageonmap.get: true
- imageonmap.getother: true
- imageonmap.explore: true
- imageonmap.exploreother: true
- imageonmap.rename: true
- imageonmap.removesplattermap: true
- imageonmap.delete: true
- imageonmap.deleteother: false
- imageonmap.bypasssize: false
- imageonmap.give: false
- imageonmap.update: true
- imageonmap.updateother: false
+ imageonmap.*:
+ description: "Grants all the user permissions (excluding administrative ones)."
+ default: true
+ children:
+ imageonmap.userender: true
+ imageonmap.new: true
+ imageonmap.list: true
+ imageonmap.listother: true
+ imageonmap.get: true
+ imageonmap.getother: true
+ imageonmap.explore: true
+ imageonmap.exploreother: true
+ imageonmap.rename: true
+ imageonmap.removesplattermap: true
+ imageonmap.delete: true
+ imageonmap.deleteother: false
+ imageonmap.bypasssize: false
+ imageonmap.give: false
+ imageonmap.update: true
+ imageonmap.updateother: false
- imageonmap.userender:
- description: "Allows you to use /tomap and related commands (/maptool getremaining). Alias of imageonmap.new."
- default: true
+ imageonmap.userender:
+ description: "Allows you to use /tomap and related commands (/maptool getremaining). Alias of imageonmap.new."
+ default: true
- imageonmap.new:
- description: "Allows you to use /tomap and related commands (/maptool getremaining)."
- default: true
+ imageonmap.new:
+ description: "Allows you to use /tomap and related commands (/maptool getremaining)."
+ default: true
- imageonmap.list:
- description: "Allows you to list the images you rendered."
- default: true
+ imageonmap.list:
+ description: "Allows you to list the images you rendered."
+ default: true
- imageonmap.listother:
- description: "Allows you to list the images a player have rendered."
- default: false
+ imageonmap.listother:
+ description: "Allows you to list the images a player have rendered."
+ default: false
- imageonmap.get:
- description: "Allows you to get a new map among the ones you already rendered, and related commands (/maptool getremaining)."
- default: true
+ imageonmap.get:
+ description: "Allows you to get a new map among the ones you already rendered, and related commands (/maptool getremaining)."
+ default: true
- imageonmap.getother:
- description: "Allows you to get a new map among the ones a player have already rendered."
- default: false
+ imageonmap.getother:
+ description: "Allows you to get a new map among the ones a player have already rendered."
+ default: false
- imageonmap.explore:
- description: "Allows you to open a GUI with all your maps."
- default: true
+ imageonmap.explore:
+ description: "Allows you to open a GUI with all your maps."
+ default: true
- imageonmap.exploreother:
- description: "Allows you to open a GUI with all of the player maps."
- default: false
+ imageonmap.exploreother:
+ description: "Allows you to open a GUI with all of the player maps."
+ default: false
- imageonmap.rename:
- description: "Allows you to rename a map you rendered in the past."
- default: true
+ imageonmap.rename:
+ description: "Allows you to rename a map you rendered in the past."
+ default: true
- imageonmap.delete:
- description: "Allows you to delete a map you rendered in the past."
- default: true
+ imageonmap.delete:
+ description: "Allows you to delete a map you rendered in the past."
+ default: true
- imageonmap.give:
- description: "Allows you to give a map to a specified player."
- default: op
-
- imageonmap.deleteother:
- description: "Allows you to delete a map a player rendered in the past."
- default: false
+ imageonmap.give:
+ description: "Allows you to give a map to a specified player."
+ default: op
- imageonmap.removesplattermap:
- description: "Allows you to remove a splatter map from a wall by sneaking and breaking a map."
- default: true
+ imageonmap.deleteother:
+ description: "Allows you to delete a map a player rendered in the past."
+ default: false
- imageonmap.administrative:
- description: "Allows you to perform administrative tasks (like /maptool migrate)."
- default: op
+ imageonmap.removesplattermap:
+ description: "Allows you to remove a splatter map from a wall by sneaking and breaking a map."
+ default: true
- imageonmap.bypasssize:
- description: "Allows you to create maps larger than the configured limit."
- default: op
+ imageonmap.administrative:
+ description: "Allows you to perform administrative tasks (like /maptool migrate)."
+ default: op
- imageonmap.update:
- description: "Allows you to update an existing map with a new image."
- default: true
+ imageonmap.bypasssize:
+ description: "Allows you to create maps larger than the configured limit."
+ default: op
- imageonmap.updateother:
- description: "Allows you to update an existing map of an other player with a new image."
- default: op
+ imageonmap.update:
+ description: "Allows you to update an existing map with a new image."
+ default: true
+
+ imageonmap.updateother:
+ description: "Allows you to update an existing map of an other player with a new image."
+ default: op