diff --git a/src/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java b/src/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java index b85df912..c2a38e80 100644 --- a/src/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java +++ b/src/com/massivecraft/factions/integration/dynmap/AreaMarkerValues.java @@ -1,5 +1,6 @@ package com.massivecraft.factions.integration.dynmap; +import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.util.MUtil; import org.dynmap.markers.AreaMarker; import org.dynmap.markers.MarkerAPI; @@ -13,68 +14,67 @@ public class AreaMarkerValues private final String label; public String getLabel() { return label; } - public AreaMarkerValues withLabel(String label) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withLabel(String label) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } private final String world; public String getWorld() { return world; } - public AreaMarkerValues withWorld(String world) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withWorld(String world) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - private final double[] x; - public double[] getX() { return x; } - public AreaMarkerValues withX(double[] x) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } - - private final double[] z; - public double[] getZ() { return z; } - public AreaMarkerValues withZ(double[] z) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + private final PS[] corners; + public PS[] getCorners() { return this.corners; } + public AreaMarkerValues withCorners() { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } private final String description; public String getDescription() { return description; } - public AreaMarkerValues withDescription(String description) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withDescription(String description) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } private final int lineColor; public int getLineColor() { return lineColor; } - public AreaMarkerValues withLineColor(int lineColor) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withLineColor(int lineColor) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } private final double lineOpacity; public double getLineOpacity() { return lineOpacity; } - public AreaMarkerValues withLineOpacity(double lineOpacity) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withLineOpacity(double lineOpacity) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } private final int lineWeight; public int getLineWeight() { return lineWeight; } - public AreaMarkerValues withLineWright(int lineWeight) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withLineWright(int lineWeight) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } private final int fillColor; public int getFillColor() { return fillColor; } - public AreaMarkerValues withFillColor(int fillColor) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withFillColor(int fillColor) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } private final double fillOpacity; public double getFillOpacity() { return fillOpacity; } - public AreaMarkerValues withFillOpacity(double fillOpacity) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withFillOpacity(double fillOpacity) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } private final boolean boost; public boolean isBoost() { return boost; } - public AreaMarkerValues withBoost(boolean boost) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } + public AreaMarkerValues withBoost(boolean boost) { return new AreaMarkerValues(label, world, corners, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } public AreaMarkerValues withStyle(DynmapStyle style) { - return new AreaMarkerValues(label, world, x, z, description, style); + return new AreaMarkerValues(label, world, corners, description, style); } + // Caches + private final double[] x; + private final double[] z; + // -------------------------------------------- // // CONSTRUCTOR // -------------------------------------------- // - public AreaMarkerValues(String label, String world, double[] x, double[] z, String description, DynmapStyle style) + public AreaMarkerValues(String label, String world, PS[] corners, String description, DynmapStyle style) { - this(label, world, x, z, description, style.getLineColor(), style.getLineOpacity(), style.getLineWeight(), style.getFillColor(), style.getFillOpacity(), style.getBoost()); + this(label, world, corners, description, style.getLineColor(), style.getLineOpacity(), style.getLineWeight(), style.getFillColor(), style.getFillOpacity(), style.getBoost()); } - public AreaMarkerValues(String label, String world, double[] x, double[] z, String description, int lineColor, double lineOpacity, int lineWeight, int fillColor, double fillOpacity, boolean boost) + public AreaMarkerValues(String label, String world, PS[] corners, String description, int lineColor, double lineOpacity, int lineWeight, int fillColor, double fillOpacity, boolean boost) { this.label = label; this.world = world; - this.x = x; - this.z = z; + this.corners = corners; this.description = description; this.lineColor = lineColor; this.lineOpacity = lineOpacity; @@ -82,6 +82,17 @@ public class AreaMarkerValues this.fillColor = fillColor; this.fillOpacity = fillOpacity; this.boost = boost; + + int sz = corners.length; + x = new double[sz]; + z = new double[sz]; + + for (int i = 0; i < sz; i++) + { + PS ps = corners[i]; + x[i] = ps.getLocationX(true); + z[i] = ps.getLocationZ(true); + } } // -------------------------------------------- // @@ -120,8 +131,8 @@ public class AreaMarkerValues this.getLabel(), false, this.getWorld(), - this.getX(), - this.getZ(), + this.x, + this.z, false // not persistent ); diff --git a/src/com/massivecraft/factions/integration/dynmap/EngineDynmap.java b/src/com/massivecraft/factions/integration/dynmap/EngineDynmap.java index 0b2e8538..40c75a0f 100644 --- a/src/com/massivecraft/factions/integration/dynmap/EngineDynmap.java +++ b/src/com/massivecraft/factions/integration/dynmap/EngineDynmap.java @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -248,40 +249,101 @@ public class EngineDynmap extends Engine { Iterator it = allChunksSource.iterator(); PS somePs = it.next(); - it.remove(); - // Create the polygon - //Set polygonChunks = new MassiveSet<>(); - //floodFillTarget(allChunksSource, polygonChunks, somePs); - //List linelist = getLineList(polygonChunks); List linelist = new MassiveList<>(); + // Create the polygon + Set polygonChunks = new MassiveSet<>(); + floodFillTarget(allChunksSource, polygonChunks, somePs); + + List polygonCorners = new MassiveList<>(); + for (PS chunk : polygonChunks) + { + for (Direction d : Direction.values()) + { + polygonCorners.add(d.getCorner(chunk)); + } + } + + Set points = new MassiveSet<>(); + for (PS corner : polygonCorners) + { + if (points.contains(corner)) + points.remove(corner); + else + points.add(corner); + } + + Map edges_h = new MassiveMap<>(); + Map edges_v = new MassiveMap<>(); + + List sorted_x = new MassiveList<>(points); + Collections.sort(sorted_x, this::xThenZ); + List sorted_z = new MassiveList<>(points); + Collections.sort(sorted_z, this::zThenX); + + // Create horizontal edges + for (int i = 0; i < points.size();) + { + int curr_z = sorted_z.get(i).getChunkZ(); + while (i < points.size() && curr_z == sorted_z.get(i+1).getChunkZ()) + { + edges_h.put(sorted_z.get(i), sorted_z.get(i+1)); + edges_h.put(sorted_z.get(i+1), sorted_z.get(i)); + i += 2; + } + } + + // Create vertical edges + for (int i = 0; i < points.size();) + { + int curr_x = sorted_x.get(i).getChunkX(); + while (i < points.size() && curr_x == sorted_x.get(i+1).getChunkX()) + { + edges_v.put(sorted_x.get(i), sorted_x.get(i+1)); + edges_v.put(sorted_x.get(i+1), sorted_x.get(i)); + i += 2; + } + } + + //List linelist = getLineList(polygonChunks); + + + linelist = new MassiveList<>(new LinkedHashSet<>(linelist)); + for (Direction d : Direction.values()) { linelist.add(d.getCorner(somePs)); } - // Calc the x and y arrays - int sz = linelist.size(); - double[] x = new double[sz]; - double[] z = new double[sz]; - - int i = 0; - for (PS ps : linelist) - { - x[i] = ps.getLocationX(true); - z[i] = ps.getLocationZ(true); - i++; - } - // Build information for specific area String markerId = calcMarkerId(world, faction); - AreaMarkerValues values = new AreaMarkerValues(faction.getName(), world, x, z, description, style); + AreaMarkerValues values = new AreaMarkerValues(faction.getName(), world, linelist.toArray(new PS[]{}), description, style); ret.put(markerId, values); } return ret; } + private int zThenX(PS a, PS b) + { + if (a.getChunkZ() < b.getChunkZ() || (a.getChunkZ().equals(b.getChunkZ()) && a.getChunkX() < b.getChunkX())) + return -1; + else if (a.equals(b)) + return 0; + else + return 1; + } + + private int xThenZ(PS a, PS b) + { + if (a.getChunkX() < b.getChunkX() || (a.getChunkX().equals(b.getChunkX()) && a.getChunkZ() < b.getChunkZ())) + return -1; + else if (a.equals(b)) + return 0; + else + return 1; + } + private static PS getMinimum(Collection pss) { int minimumX = Integer.MAX_VALUE; diff --git a/src/com/massivecraft/factions/util/EnumerationUtil.java b/src/com/massivecraft/factions/util/EnumerationUtil.java index f0690b5d..3abbe52e 100644 --- a/src/com/massivecraft/factions/util/EnumerationUtil.java +++ b/src/com/massivecraft/factions/util/EnumerationUtil.java @@ -22,7 +22,39 @@ public class EnumerationUtil "LECTERN", // Minecraft 1.14 "BEEHIVE", // Minecraft 1.15 "BEE_NEST", // Minecraft 1.5 - "FLOWER_POT" // Minecraft 1.? + "FLOWER_POT", // Minecraft 1.? + + // The various flower pots, they had to make each one a different material -.- + "POTTED_ACACIA_SAPLING", // Minecraft 1.13 + "POTTED_ALLIUM", // Minecraft 1.13 + "POTTED_AZURE_BLUET", // Minecraft 1.13 + "POTTED_BAMBOO", // Minecraft 1.13 + "POTTED_BIRCH_SAPLING", // Minecraft 1.13 + "POTTED_BLUE_ORCHID", // Minecraft 1.13 + "POTTED_BROWN_MUSHROOM", // Minecraft 1.13 + "POTTED_CACTUS", // Minecraft 1.13 + "POTTED_CACTUS", // Minecraft 1.13 + "POTTED_CORNFLOWER", // Minecraft 1.13 + "POTTED_DANDELION", // Minecraft 1.13 + "POTTED_DARK_OAK_SAPLING", // Minecraft 1.13 + "POTTED_DEAD_BUSH", // Minecraft 1.13 + "POTTED_FERN", // Minecraft 1.13 + "POTTED_JUNGLE_SAPLING", // Minecraft 1.13 + "POTTED_LILY_OF_THE_VALLEY", // Minecraft 1.13 + "POTTED_OAK_SAPLING", // Minecraft 1.13 + "POTTED_ORANGE_TULIP", // Minecraft 1.13 + "POTTED_OXEYE_DAISY", // Minecraft 1.13 + "POTTED_PINK_TULIP", // Minecraft 1.13 + "POTTED_POPPY", // Minecraft 1.13 + "POTTED_RED_MUSHROOM", // Minecraft 1.13 + "POTTED_RED_TULIP", // Minecraft 1.13 + "POTTED_SPRUCE_SAPLING", // Minecraft 1.13 + "POTTED_WHITE_TULIP", // Minecraft 1.13 + "POTTED_WITHER_ROSE", // Minecraft 1.13 + "POTTED_CRIMSON_FUNGUS", // Minecraft 1.16 + "POTTED_CRIMSON_ROOTS", // Minecraft 1.16 + "POTTED_WARPED_FUNGUS", // Minecraft 1.16 + "POTTED_WARPED_ROOTS" // Minecraft 1.16 ); public static boolean isMaterialEditOnInteract(Material material) @@ -54,7 +86,8 @@ public class EnumerationUtil "TRAPPED_CHEST", // Minecraft 1.? "SIGN", // Minecraft 1.? "WOOD_DOOR", // Minecraft 1.? - "IRON_DOOR" // Minecraft 1.? + "IRON_DOOR", // Minecraft 1.? + "BONE_MEAL" // Minecraft 1.? ); public static boolean isMaterialEditTool(Material material) @@ -73,7 +106,7 @@ public class EnumerationUtil "OAK_FENCE_GATE", "ACACIA_DOOR", "ACACIA_TRAPDOOR", - "AKACIA_FENCE_GATE", + "ACACIA_FENCE_GATE", "BIRCH_DOOR", "BIRCH_TRAPDOOR", "BIRCH_FENCE_GATE", @@ -85,7 +118,15 @@ public class EnumerationUtil "JUNGLE_FENCE_GATE", "SPRUCE_DOOR", "SPRUCE_TRAPDOOR", - "SPRUCE_FENCE_GATE" + "SPRUCE_FENCE_GATE", + + // Minecraft 1.16 + "CRIMSON_DOOR", + "CRIMSON_TRAPDOOR", + "CRIMSON_FENCE_GATE", + "WARPED_DOOR", + "WARPED_TRAPDOOR", + "WARPED_FENCE_GATE" ); public static boolean isMaterialDoor(Material material) @@ -113,6 +154,8 @@ public class EnumerationUtil "DROPPER", "BARREL", // Minecraft 1.14 "BLAST_FURNACE", // Minecraft 1.14 + "SMOKER", // 1.14 + "RESPAWN_ANCHOR", // 1.16 // The various shulker boxes, they had to make each one a different material -.- "SHULKER_BOX", @@ -225,7 +268,9 @@ public class EnumerationUtil "DROWNED", // Minecraft 1.13 "PILLAGER", // Minecraft 1.14 "RAVAGER", // Minercraft 1.14 - "ZOMBIFIED_PIGLIN" // Minecraft 1.16 (rename of PIG_ZOMBIE) + "ZOMBIFIED_PIGLIN", // Minecraft 1.16 (rename of PIG_ZOMBIE) + "HOGLIN", // Minecraft 1.16 + "ZOGLIN" // 1.16 ); public static boolean isEntityTypeMonster(EntityType entityType) @@ -264,7 +309,8 @@ public class EnumerationUtil "FOX", // Minecraft 1.14 "PANDA", // Minecraft 1.14 "LLAMA", // Minecraft 1.14 - "LLAMA_SPIT" // Minecraft 1.14 + "LLAMA_SPIT", // Minecraft 1.14 + "STRIDER" // Minecraft 1.16 ); public static boolean isEntityTypeAnimal(EntityType entityType)