refactor ...
This commit is contained in:
parent
b3411f89a8
commit
05fbb6b416
|
@ -44,6 +44,7 @@ import fr.moribus.imageonmap.commands.maptool.GetRemainingCommand;
|
|||
import fr.moribus.imageonmap.commands.maptool.GiveCommand;
|
||||
import fr.moribus.imageonmap.commands.maptool.ListCommand;
|
||||
import fr.moribus.imageonmap.commands.maptool.NewCommand;
|
||||
import fr.moribus.imageonmap.commands.maptool.RemotePlacingCommand;
|
||||
import fr.moribus.imageonmap.commands.maptool.RenameCommand;
|
||||
import fr.moribus.imageonmap.commands.maptool.UpdateCommand;
|
||||
import fr.moribus.imageonmap.image.ImageIOExecutor;
|
||||
|
@ -158,12 +159,14 @@ public final class ImageOnMap extends QuartzPlugin {
|
|||
GetRemainingCommand.class,
|
||||
ExploreCommand.class,
|
||||
//MigrateCommand.class,//Removed for now doesn't work nor is useful, maybe useful later on
|
||||
UpdateCommand.class
|
||||
UpdateCommand.class,
|
||||
RemotePlacingCommand.class
|
||||
);
|
||||
|
||||
Commands.registerShortcut(commandGroupName, NewCommand.class, "tomap");
|
||||
Commands.registerShortcut(commandGroupName, ExploreCommand.class, "maps");
|
||||
Commands.registerShortcut(commandGroupName, GiveCommand.class, "givemap");
|
||||
Commands.registerShortcut(commandGroupName, RemotePlacingCommand.class, "placemap");
|
||||
|
||||
if (PluginConfiguration.CHECK_FOR_UPDATES.get()) {
|
||||
UpdateChecker.boot("imageonmap.26585");
|
||||
|
|
|
@ -63,7 +63,8 @@ public enum Permissions {
|
|||
BYPASS_IMAGE_LIMIT("imageonmap.bypassimagelimit"),
|
||||
BYPASS_MAP_LIMIT("imageonmap.bypassmaplimit"),
|
||||
GIVE("imageonmap.give"),
|
||||
BYPASS_WHITELIST("imageonmap.bypasswhitelist");
|
||||
BYPASS_WHITELIST("imageonmap.bypasswhitelist"),
|
||||
REMOTE_PLACING("imageonmap.remoteplacing");
|
||||
|
||||
private final String permission;
|
||||
private final String[] aliases;
|
||||
|
|
|
@ -125,6 +125,29 @@ public class ImageUtils {
|
|||
|
||||
}
|
||||
|
||||
public static ScalingType scalingTypeFromName(String resize) {
|
||||
switch (resize) {
|
||||
case "stretch":
|
||||
case "stretched":
|
||||
case "resize-stretched":
|
||||
return ScalingType.STRETCHED;
|
||||
|
||||
case "cover":
|
||||
case "covered":
|
||||
case "resize-covered":
|
||||
return ScalingType.COVERED;
|
||||
|
||||
case "contain":
|
||||
case "contained":
|
||||
case "resize-contained":
|
||||
case "resize":
|
||||
return ScalingType.CONTAINED;
|
||||
|
||||
default:
|
||||
return ScalingType.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ScalingType {
|
||||
NONE,
|
||||
CONTAINED,
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package fr.moribus.imageonmap.map;
|
||||
|
||||
public class MapIndexes {
|
||||
|
||||
private final int columnIndex;
|
||||
private final int rowIndex;
|
||||
|
||||
public MapIndexes(int rowIndex, int columnIndex) {
|
||||
this.rowIndex = rowIndex;
|
||||
this.columnIndex = columnIndex;
|
||||
}
|
||||
|
||||
public int getColumnIndex() {
|
||||
return columnIndex;
|
||||
}
|
||||
|
||||
public int getRowIndex() {
|
||||
return rowIndex;
|
||||
}
|
||||
}
|
|
@ -36,11 +36,20 @@
|
|||
|
||||
package fr.moribus.imageonmap.map;
|
||||
|
||||
import fr.zcraft.quartzlib.tools.PluginLogger;
|
||||
import fr.zcraft.quartzlib.tools.world.WorldUtils;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import jdk.internal.net.http.common.Pair;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PosterMap extends ImageMap {
|
||||
protected final int[] mapsIDs;
|
||||
|
@ -206,4 +215,84 @@ public class PosterMap extends ImageMap {
|
|||
throw new IllegalArgumentException("Invalid map ID");
|
||||
}
|
||||
|
||||
public int getSortedIndex(int mapID) {
|
||||
int[] ids = mapsIDs.clone();
|
||||
Arrays.sort(ids);
|
||||
for (int i : ids) {
|
||||
PluginLogger.info("" + i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < mapsIDs.length; i++) {
|
||||
if (ids[i] == mapID) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid map ID");
|
||||
}
|
||||
|
||||
public MapIndexes getIndexes(int mapID) {
|
||||
int index = getSortedIndex(mapID);
|
||||
PluginLogger.info(rowCount + " " + columnCount + " " + index);
|
||||
return new MapIndexes(index / columnCount, index % columnCount);
|
||||
}
|
||||
|
||||
public Location findLocationFirstFrame(ItemFrame frame, Player player) {
|
||||
final ImageMap map = MapManager.getMap(frame.getItem());
|
||||
if (!(map instanceof PosterMap)) {
|
||||
return null;
|
||||
}
|
||||
PosterMap poster = (PosterMap) map;
|
||||
if (!poster.hasColumnData()) {
|
||||
return null;
|
||||
}
|
||||
int mapID = MapManager.getMapIdFromItemStack(frame.getItem());
|
||||
|
||||
BlockFace bf = WorldUtils.get4thOrientation(player.getLocation());
|
||||
|
||||
MapIndexes mapindexes = getIndexes(mapID);
|
||||
int row = mapindexes.getRowIndex();
|
||||
int column = mapindexes.getColumnIndex();
|
||||
Location loc = frame.getLocation();
|
||||
PluginLogger.info("\n\nlocalization of the initial clicked frame " + loc);
|
||||
PluginLogger.info("row " + row + " col " + column);
|
||||
switch (frame.getFacing().getOppositeFace()) {
|
||||
case UP:
|
||||
case DOWN:
|
||||
switch (bf) {
|
||||
case NORTH:
|
||||
loc.add(-row, 0, column);
|
||||
break;
|
||||
case SOUTH:
|
||||
loc.add(row, 0, -column);
|
||||
break;
|
||||
case WEST:
|
||||
loc.add(row, 0, column);
|
||||
break;
|
||||
case EAST:
|
||||
loc.add(-row, 0, -column);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + bf);
|
||||
}
|
||||
break;
|
||||
|
||||
case EAST:
|
||||
loc.add(0, -row, -column);
|
||||
break;
|
||||
case WEST:
|
||||
loc.add(0, -row, column);
|
||||
break;
|
||||
case NORTH:
|
||||
loc.add(-column, -row, 0);
|
||||
break;
|
||||
case SOUTH:
|
||||
loc.add(column, -row, 0);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + bf);
|
||||
}
|
||||
PluginLogger.info("\n\nlocalization of the first frame " + loc);
|
||||
return loc;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
|
||||
package fr.moribus.imageonmap.ui;
|
||||
|
||||
import fr.moribus.imageonmap.map.PosterMap;
|
||||
import fr.zcraft.quartzlib.tools.PluginLogger;
|
||||
import fr.zcraft.quartzlib.tools.world.FlatLocation;
|
||||
import fr.zcraft.quartzlib.tools.world.WorldUtils;
|
||||
|
@ -49,7 +48,6 @@ import org.bukkit.entity.Entity;
|
|||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class PosterOnASurface {
|
||||
public FlatLocation loc1;
|
||||
|
@ -164,11 +162,14 @@ public class PosterOnASurface {
|
|||
boolean isFloor = facing.equals(BlockFace.DOWN);
|
||||
boolean isCeiling = facing.equals(BlockFace.UP);
|
||||
Location loc = startingLocation;
|
||||
|
||||
int x = 0;
|
||||
int z = 0;
|
||||
PluginLogger.info(loc.toString()); //TODO to delete
|
||||
for (int r = 0; r < rows; r++) {
|
||||
for (int c = 0; c < columns; c++) {
|
||||
PluginLogger.info("column " + c);
|
||||
PluginLogger.info("row " + r);
|
||||
|
||||
itemFramesLocationMap.put(loc.clone(), getFrameAt(loc, facing));
|
||||
//do a row
|
||||
if (isWall || isFloor) {
|
||||
|
@ -219,7 +220,6 @@ public class PosterOnASurface {
|
|||
|
||||
|
||||
}
|
||||
itemFramesLocationMap.put(loc.clone(), getFrameAt(loc, facing));
|
||||
if (isWall) {
|
||||
loc = loc.add(-x, 1, -z);
|
||||
} else if (isFloor || isCeiling) {
|
||||
|
|
|
@ -43,7 +43,6 @@ import fr.moribus.imageonmap.map.MapManager;
|
|||
import fr.moribus.imageonmap.map.PosterMap;
|
||||
import fr.zcraft.quartzlib.components.i18n.I;
|
||||
import fr.zcraft.quartzlib.tools.PluginLogger;
|
||||
import fr.zcraft.quartzlib.tools.items.GlowEffect;
|
||||
import fr.zcraft.quartzlib.tools.items.ItemStackBuilder;
|
||||
import fr.zcraft.quartzlib.tools.runners.RunTask;
|
||||
import fr.zcraft.quartzlib.tools.text.MessageSender;
|
||||
|
@ -127,7 +126,7 @@ public abstract class SplatterMapManager {
|
|||
* @return The modified item stack. The instance may be different if the passed item stack is not a craft itemstack.
|
||||
*/
|
||||
public static ItemStack addSplatterAttribute(final ItemStack itemStack) {
|
||||
itemStack.addUnsafeEnchantment(Enchantment.LURE,1);
|
||||
itemStack.addUnsafeEnchantment(Enchantment.LURE, 1);
|
||||
//TODO check if safe guard for duplication XP still works
|
||||
return itemStack;
|
||||
}
|
||||
|
@ -330,13 +329,16 @@ public abstract class SplatterMapManager {
|
|||
return null;
|
||||
}
|
||||
|
||||
Location startingLocation = poster.findLocationFirstFrame(startFrame,player);
|
||||
|
||||
Map<Location, ItemFrame>
|
||||
itemFrameLocations =
|
||||
PosterOnASurface.getItemFramesLocation(player, startFrame.getLocation(), startFrame.getFacing(),
|
||||
PosterOnASurface.getItemFramesLocation(player, startingLocation, startFrame.getFacing(),
|
||||
poster.getRowCount(), poster.getColumnCount());
|
||||
|
||||
//TODO check if it is the correct map id and check the why it delete more than it should and out of place
|
||||
for (Map.Entry<Location, ItemFrame> entry : itemFrameLocations.entrySet()) {
|
||||
ItemFrame frame = itemFrameLocations.get(entry.getKey());
|
||||
PluginLogger.info("Frame to delete " + frame);
|
||||
if (frame != null) {
|
||||
removePropertiesFromFrames(player, frame);
|
||||
frame.setItem(null);
|
||||
|
|
Loading…
Reference in New Issue