Update enumeration util

Seems I also made some change to the DYnmap engine. Let's hope I didn't break anything.
This commit is contained in:
Magnus Ulf 2021-05-23 13:54:20 +02:00
parent 03c9270d29
commit 104e77865e
3 changed files with 168 additions and 49 deletions

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.integration.dynmap; package com.massivecraft.factions.integration.dynmap;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import org.dynmap.markers.AreaMarker; import org.dynmap.markers.AreaMarker;
import org.dynmap.markers.MarkerAPI; import org.dynmap.markers.MarkerAPI;
@ -13,68 +14,67 @@ public class AreaMarkerValues
private final String label; private final String label;
public String getLabel() { return 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; private final String world;
public String getWorld() { return 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; private final PS[] corners;
public double[] getX() { return x; } public PS[] getCorners() { return this.corners; }
public AreaMarkerValues withX(double[] x) { return new AreaMarkerValues(label, world, x, z, description, lineColor, lineOpacity, lineWeight, fillColor, fillOpacity, boost); } public AreaMarkerValues withCorners() { return new AreaMarkerValues(label, world, corners, 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 String description; private final String description;
public String getDescription() { return 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; private final int lineColor;
public int getLineColor() { return 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; private final double lineOpacity;
public double getLineOpacity() { return 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; private final int lineWeight;
public int getLineWeight() { return 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; private final int fillColor;
public int getFillColor() { return 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; private final double fillOpacity;
public double getFillOpacity() { return 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; private final boolean boost;
public boolean isBoost() { return 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) 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 // 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.label = label;
this.world = world; this.world = world;
this.x = x; this.corners = corners;
this.z = z;
this.description = description; this.description = description;
this.lineColor = lineColor; this.lineColor = lineColor;
this.lineOpacity = lineOpacity; this.lineOpacity = lineOpacity;
@ -82,6 +82,17 @@ public class AreaMarkerValues
this.fillColor = fillColor; this.fillColor = fillColor;
this.fillOpacity = fillOpacity; this.fillOpacity = fillOpacity;
this.boost = boost; 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(), this.getLabel(),
false, false,
this.getWorld(), this.getWorld(),
this.getX(), this.x,
this.getZ(), this.z,
false // not persistent false // not persistent
); );

View File

@ -30,6 +30,7 @@ import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -248,40 +249,101 @@ public class EngineDynmap extends Engine
{ {
Iterator<PS> it = allChunksSource.iterator(); Iterator<PS> it = allChunksSource.iterator();
PS somePs = it.next(); PS somePs = it.next();
it.remove();
// Create the polygon
//Set<PS> polygonChunks = new MassiveSet<>();
//floodFillTarget(allChunksSource, polygonChunks, somePs);
//List<PS> linelist = getLineList(polygonChunks);
List<PS> linelist = new MassiveList<>(); List<PS> linelist = new MassiveList<>();
// Create the polygon
Set<PS> polygonChunks = new MassiveSet<>();
floodFillTarget(allChunksSource, polygonChunks, somePs);
List<PS> polygonCorners = new MassiveList<>();
for (PS chunk : polygonChunks)
{
for (Direction d : Direction.values())
{
polygonCorners.add(d.getCorner(chunk));
}
}
Set<PS> points = new MassiveSet<>();
for (PS corner : polygonCorners)
{
if (points.contains(corner))
points.remove(corner);
else
points.add(corner);
}
Map<PS, PS> edges_h = new MassiveMap<>();
Map<PS, PS> edges_v = new MassiveMap<>();
List<PS> sorted_x = new MassiveList<>(points);
Collections.sort(sorted_x, this::xThenZ);
List<PS> 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<PS> linelist = getLineList(polygonChunks);
linelist = new MassiveList<>(new LinkedHashSet<>(linelist));
for (Direction d : Direction.values()) for (Direction d : Direction.values())
{ {
linelist.add(d.getCorner(somePs)); 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 // Build information for specific area
String markerId = calcMarkerId(world, faction); 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); ret.put(markerId, values);
} }
return ret; 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<PS> pss) private static PS getMinimum(Collection<PS> pss)
{ {
int minimumX = Integer.MAX_VALUE; int minimumX = Integer.MAX_VALUE;

View File

@ -22,7 +22,39 @@ public class EnumerationUtil
"LECTERN", // Minecraft 1.14 "LECTERN", // Minecraft 1.14
"BEEHIVE", // Minecraft 1.15 "BEEHIVE", // Minecraft 1.15
"BEE_NEST", // Minecraft 1.5 "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) public static boolean isMaterialEditOnInteract(Material material)
@ -54,7 +86,8 @@ public class EnumerationUtil
"TRAPPED_CHEST", // Minecraft 1.? "TRAPPED_CHEST", // Minecraft 1.?
"SIGN", // Minecraft 1.? "SIGN", // Minecraft 1.?
"WOOD_DOOR", // Minecraft 1.? "WOOD_DOOR", // Minecraft 1.?
"IRON_DOOR" // Minecraft 1.? "IRON_DOOR", // Minecraft 1.?
"BONE_MEAL" // Minecraft 1.?
); );
public static boolean isMaterialEditTool(Material material) public static boolean isMaterialEditTool(Material material)
@ -73,7 +106,7 @@ public class EnumerationUtil
"OAK_FENCE_GATE", "OAK_FENCE_GATE",
"ACACIA_DOOR", "ACACIA_DOOR",
"ACACIA_TRAPDOOR", "ACACIA_TRAPDOOR",
"AKACIA_FENCE_GATE", "ACACIA_FENCE_GATE",
"BIRCH_DOOR", "BIRCH_DOOR",
"BIRCH_TRAPDOOR", "BIRCH_TRAPDOOR",
"BIRCH_FENCE_GATE", "BIRCH_FENCE_GATE",
@ -85,7 +118,15 @@ public class EnumerationUtil
"JUNGLE_FENCE_GATE", "JUNGLE_FENCE_GATE",
"SPRUCE_DOOR", "SPRUCE_DOOR",
"SPRUCE_TRAPDOOR", "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) public static boolean isMaterialDoor(Material material)
@ -113,6 +154,8 @@ public class EnumerationUtil
"DROPPER", "DROPPER",
"BARREL", // Minecraft 1.14 "BARREL", // Minecraft 1.14
"BLAST_FURNACE", // 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 -.- // The various shulker boxes, they had to make each one a different material -.-
"SHULKER_BOX", "SHULKER_BOX",
@ -225,7 +268,9 @@ public class EnumerationUtil
"DROWNED", // Minecraft 1.13 "DROWNED", // Minecraft 1.13
"PILLAGER", // Minecraft 1.14 "PILLAGER", // Minecraft 1.14
"RAVAGER", // Minercraft 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) public static boolean isEntityTypeMonster(EntityType entityType)
@ -264,7 +309,8 @@ public class EnumerationUtil
"FOX", // Minecraft 1.14 "FOX", // Minecraft 1.14
"PANDA", // Minecraft 1.14 "PANDA", // Minecraft 1.14
"LLAMA", // 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) public static boolean isEntityTypeAnimal(EntityType entityType)