mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
Add icons in pl3xmap, remove old inbuilt icons and add new custom map icons that work on all three platforms
This commit is contained in:
1 parent
278f1876b5
commit
9d57b76c79
8 files changed
+119
-21
No files matched your search
@@ -44,8 +44,6 @@ public class Settings {
|
||||
private String mapPlugin;
|
||||
private boolean mapPublicHomes;
|
||||
private boolean mapWarps;
|
||||
private String mapPublicHomeMarkerIconID;
|
||||
private String mapWarpMarkerIconID;
|
||||
private String mapPublicHomeMarkerSet;
|
||||
private String mapWarpMarkerSet;
|
||||
|
||||
@@ -170,8 +168,6 @@ public class Settings {
|
||||
|
||||
this.mapPublicHomes = config.getBoolean("map_integration.markers.public_homes.show", true);
|
||||
this.mapWarps = config.getBoolean("map_integration.markers.warps.show", true);
|
||||
this.mapPublicHomeMarkerIconID = config.getString("map_integration.markers.public_homes.icon_id", "house");
|
||||
this.mapWarpMarkerIconID = config.getString("map_integration.markers.warps.icon_id", "sign");
|
||||
this.mapPublicHomeMarkerSet = config.getString("map_integration.markers.public_homes.set_name", "Public Homes");
|
||||
this.mapWarpMarkerSet = config.getString("map_integration.markers.warps.set_name", "Warps");
|
||||
|
||||
@@ -252,14 +248,6 @@ public class Settings {
|
||||
return mapWarps;
|
||||
}
|
||||
|
||||
public String getMapPublicHomeMarkerIconID() {
|
||||
return mapPublicHomeMarkerIconID;
|
||||
}
|
||||
|
||||
public String getMapWarpMarkerIconID() {
|
||||
return mapWarpMarkerIconID;
|
||||
}
|
||||
|
||||
public String getMapPublicHomeMarkerSet() {
|
||||
return mapPublicHomeMarkerSet;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ public class BlueMap extends Map {
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
private static final HashMap<String, Boolean> queuedWarps = new HashMap<>();
|
||||
private static final HashMap<String, Boolean> queuedPublicHomes = new HashMap<>();
|
||||
private static String warpMarkerImageAddress;
|
||||
private static String publicHomeMarkerImageAddress;
|
||||
|
||||
private void executeQueuedOperations() {
|
||||
try {
|
||||
@@ -67,6 +69,9 @@ public class BlueMap extends Map {
|
||||
for (BlueMapMap map : blueMapWorld.getMaps()) {
|
||||
POIMarker marker = markerSet.createPOIMarker(markerId, map, warp.getX(), warp.getY(), warp.getZ());
|
||||
marker.setLabel(getWarpInfoMenu(warp));
|
||||
if (warpMarkerImageAddress != null) {
|
||||
marker.setIcon(warpMarkerImageAddress, marker.getAnchor());
|
||||
}
|
||||
}
|
||||
try {
|
||||
markerAPI.save();
|
||||
@@ -113,6 +118,9 @@ public class BlueMap extends Map {
|
||||
for (BlueMapMap map : blueMapWorld.getMaps()) {
|
||||
POIMarker marker = markerSet.createPOIMarker(markerId, map, home.getX(), home.getY(), home.getZ());
|
||||
marker.setLabel(getPublicHomeInfoMenu(home));
|
||||
if (publicHomeMarkerImageAddress != null) {
|
||||
marker.setIcon(publicHomeMarkerImageAddress, marker.getAnchor());
|
||||
}
|
||||
}
|
||||
try {
|
||||
markerAPI.save();
|
||||
@@ -167,6 +175,9 @@ public class BlueMap extends Map {
|
||||
// Create Marker Set
|
||||
BlueMapAPI.onEnable(api -> {
|
||||
try {
|
||||
publicHomeMarkerImageAddress = api.createImage(getPublicHomeIcon(), "huskhomes/" + PUBLIC_HOME_MARKER_IMAGE_NAME);
|
||||
warpMarkerImageAddress = api.createImage(getWarpIcon(), "huskhomes/" + WARP_MARKER_IMAGE_NAME);
|
||||
|
||||
MarkerAPI markerAPI = api.getMarkerAPI();
|
||||
|
||||
MarkerSet publicHomeMarkerSet = markerAPI.getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID).orElse(markerAPI.createMarkerSet(PUBLIC_HOMES_MARKER_SET_ID));
|
||||
|
||||
@@ -10,6 +10,14 @@ import org.dynmap.DynmapAPI;
|
||||
import org.dynmap.markers.Marker;
|
||||
import org.dynmap.markers.MarkerSet;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
@@ -18,6 +26,23 @@ public class DynMap extends Map {
|
||||
|
||||
private static Plugin dynMap;
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
private static final double MARKER_ICON_SCALE = 0.75;
|
||||
|
||||
// Returns the marker icons from the plugin resources in the correct format and scaled to look good with Dynmap
|
||||
private InputStream getScaledMarkerIconStream(BufferedImage image) {
|
||||
try {
|
||||
BufferedImage scaledImage = new BufferedImage((int)(32 * MARKER_ICON_SCALE), (int)(32 * MARKER_ICON_SCALE), image.getType());
|
||||
AffineTransform scaleInstance = AffineTransform.getScaleInstance(MARKER_ICON_SCALE, MARKER_ICON_SCALE);
|
||||
AffineTransformOp scaleOp = new AffineTransformOp(scaleInstance, AffineTransformOp.TYPE_BILINEAR);
|
||||
scaleOp.filter(image, scaledImage);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ImageIO.write(scaledImage, "png", outputStream);
|
||||
return new ByteArrayInputStream(outputStream.toByteArray());
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An exception occurred converting marker icon image data!", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeWarpMarker(String warpName) {
|
||||
@@ -52,7 +77,7 @@ public class DynMap extends Map {
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynMap;
|
||||
|
||||
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet(WARPS_MARKER_SET_ID);
|
||||
Marker m = markerSet.createMarker(markerId, warp.getName(), warp.getWorldName(), warp.getX(), warp.getY(), warp.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(HuskHomes.getSettings().getMapWarpMarkerIconID()), false);
|
||||
Marker m = markerSet.createMarker(markerId, warp.getName(), warp.getWorldName(), warp.getX(), warp.getY(), warp.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(WARP_MARKER_IMAGE_NAME), false);
|
||||
|
||||
m.setDescription(getWarpInfoMenu(warp));
|
||||
} catch (Exception e) {
|
||||
@@ -68,7 +93,7 @@ public class DynMap extends Map {
|
||||
DynmapAPI dynmapAPI = (DynmapAPI) dynMap;
|
||||
|
||||
MarkerSet markerSet = dynmapAPI.getMarkerAPI().getMarkerSet(PUBLIC_HOMES_MARKER_SET_ID);
|
||||
Marker m = markerSet.createMarker(markerId, home.getName(), home.getWorldName(), home.getX(), home.getY(), home.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(HuskHomes.getSettings().getMapPublicHomeMarkerIconID()), false);
|
||||
Marker m = markerSet.createMarker(markerId, home.getName(), home.getWorldName(), home.getX(), home.getY(), home.getZ(), dynmapAPI.getMarkerAPI().getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME), false);
|
||||
|
||||
m.setDescription(getPublicHomeInfoMenu(home));
|
||||
} catch (Exception e) {
|
||||
@@ -87,6 +112,9 @@ public class DynMap extends Map {
|
||||
return;
|
||||
}
|
||||
|
||||
dynmapAPI.getMarkerAPI().createMarkerIcon(WARP_MARKER_IMAGE_NAME, "Warp", getScaledMarkerIconStream(getWarpIcon()));
|
||||
dynmapAPI.getMarkerAPI().createMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME, "Public Home", getScaledMarkerIconStream(getPublicHomeIcon()));
|
||||
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package me.william278.huskhomes2.integrations.map;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
|
||||
|
||||
public abstract class Map {
|
||||
@@ -10,9 +17,37 @@ public abstract class Map {
|
||||
public Map() {
|
||||
}
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
public static final String PUBLIC_HOMES_MARKER_SET_ID = "huskhomes.public_homes";
|
||||
public static final String WARPS_MARKER_SET_ID = "huskhomes.warps";
|
||||
|
||||
public static final String PUBLIC_HOME_MARKER_IMAGE_NAME = "public_home";
|
||||
public static final String WARP_MARKER_IMAGE_NAME = "warp";
|
||||
|
||||
public BufferedImage getWarpIcon() {
|
||||
return getMarkerIcon(WARP_MARKER_IMAGE_NAME);
|
||||
}
|
||||
|
||||
public BufferedImage getPublicHomeIcon() {
|
||||
return getMarkerIcon(PUBLIC_HOME_MARKER_IMAGE_NAME);
|
||||
}
|
||||
|
||||
private BufferedImage getMarkerIcon(String name) {
|
||||
final String filePath = "marker-icons" + File.separator + name + ".png";
|
||||
File file = new File(plugin.getDataFolder(), filePath);
|
||||
if (!file.exists()) {
|
||||
plugin.saveResource(filePath, false);
|
||||
}
|
||||
BufferedImage image = null;
|
||||
try {
|
||||
image = ImageIO.read(file);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "Failed to load " + name + " marker icon image!", e);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public abstract void addWarpMarker(Warp warp);
|
||||
|
||||
public abstract void removeWarpMarker(String warpName);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.william278.huskhomes2.integrations.map;
|
||||
|
||||
import me.william278.huskhomes2.HuskHomes;
|
||||
import me.william278.huskhomes2.data.DataManager;
|
||||
import me.william278.huskhomes2.teleport.points.Home;
|
||||
import me.william278.huskhomes2.teleport.points.Warp;
|
||||
import net.pl3x.map.api.Key;
|
||||
@@ -13,12 +14,17 @@ import net.pl3x.map.api.marker.MarkerOptions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Pl3xMap extends Map {
|
||||
|
||||
private final HashMap<String,SimpleLayerProvider> publicHomeProviders = new HashMap<>();
|
||||
private final HashMap<String,SimpleLayerProvider> warpProviders = new HashMap<>();
|
||||
private final static int MARKER_SIZE = 20;
|
||||
private final static HuskHomes plugin = HuskHomes.getInstance();
|
||||
|
||||
@Override
|
||||
public void addWarpMarker(Warp warp) {
|
||||
@@ -27,8 +33,8 @@ public class Pl3xMap extends Map {
|
||||
if (warpProviders.containsKey(world.getName())) {
|
||||
Icon marker = Marker.icon(
|
||||
Point.of(warp.getX(), warp.getZ()),
|
||||
Key.of(HuskHomes.getSettings().getMapWarpMarkerIconID()),
|
||||
10);
|
||||
Key.of(WARP_MARKER_IMAGE_NAME),
|
||||
MARKER_SIZE);
|
||||
marker.markerOptions(MarkerOptions.builder()
|
||||
.hoverTooltip(warp.getName())
|
||||
.clickTooltip(getWarpInfoMenu(warp))
|
||||
@@ -61,8 +67,8 @@ public class Pl3xMap extends Map {
|
||||
if (publicHomeProviders.containsKey(world.getName())) {
|
||||
Icon marker = Marker.icon(
|
||||
Point.of(home.getX(), home.getZ()),
|
||||
Key.of(HuskHomes.getSettings().getMapPublicHomeMarkerIconID()),
|
||||
10);
|
||||
Key.of(PUBLIC_HOME_MARKER_IMAGE_NAME),
|
||||
MARKER_SIZE);
|
||||
marker.markerOptions(MarkerOptions.builder()
|
||||
.hoverTooltip(home.getName())
|
||||
.clickTooltip(getPublicHomeInfoMenu(home))
|
||||
@@ -92,6 +98,15 @@ public class Pl3xMap extends Map {
|
||||
@Override
|
||||
public void initialize() {
|
||||
net.pl3x.map.api.Pl3xMap mapAPI = Pl3xMapProvider.get();
|
||||
|
||||
// Register map icons
|
||||
if (!Pl3xMapProvider.get().iconRegistry().hasEntry(Key.of(PUBLIC_HOME_MARKER_IMAGE_NAME))) {
|
||||
Pl3xMapProvider.get().iconRegistry().register(Key.of(PUBLIC_HOME_MARKER_IMAGE_NAME), getPublicHomeIcon());
|
||||
}
|
||||
if (!Pl3xMapProvider.get().iconRegistry().hasEntry(Key.of(WARP_MARKER_IMAGE_NAME))) {
|
||||
Pl3xMapProvider.get().iconRegistry().register(Key.of(WARP_MARKER_IMAGE_NAME), getWarpIcon());
|
||||
}
|
||||
|
||||
for (net.pl3x.map.api.MapWorld world : mapAPI.mapWorlds()) {
|
||||
// Register public home map layer
|
||||
SimpleLayerProvider publicHomeProvider =
|
||||
@@ -106,7 +121,7 @@ public class Pl3xMap extends Map {
|
||||
|
||||
// Register warps map layer
|
||||
SimpleLayerProvider warpProvider =
|
||||
SimpleLayerProvider.builder(HuskHomes.getSettings().getMapPublicHomeMarkerSet())
|
||||
SimpleLayerProvider.builder(HuskHomes.getSettings().getMapWarpMarkerSet())
|
||||
.showControls(true)
|
||||
.defaultHidden(false)
|
||||
.layerPriority(7)
|
||||
@@ -115,6 +130,29 @@ public class Pl3xMap extends Map {
|
||||
world.layerRegistry().register(Key.of(WARPS_MARKER_SET_ID), warpProvider);
|
||||
warpProviders.put(world.name(), warpProvider);
|
||||
}
|
||||
|
||||
// Populate map with markers
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
if (HuskHomes.getSettings().showPublicHomesOnMap()) {
|
||||
for (Home home : DataManager.getPublicHomes(connection)) {
|
||||
if (!HuskHomes.getSettings().doBungee() || home.getServer().equals(HuskHomes.getSettings().getServerID())) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> addPublicHomeMarker(home));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (HuskHomes.getSettings().showWarpsOnMap()) {
|
||||
for (Warp warp : DataManager.getWarps(connection)) {
|
||||
if (!HuskHomes.getSettings().doBungee() || warp.getServer().equals(HuskHomes.getSettings().getServerID())) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> addWarpMarker(warp));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred adding homes and warps to the DynMap");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -73,11 +73,9 @@ map_integration:
|
||||
public_homes:
|
||||
show: true
|
||||
set_name: 'Public Homes'
|
||||
icon_id: 'house'
|
||||
warps:
|
||||
show: true
|
||||
set_name: 'Warps'
|
||||
icon_id: 'sign'
|
||||
economy_integration:
|
||||
enabled: false
|
||||
free_home_slots: 5
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 661 B |
Binary file not shown.
|
After Width: | Height: | Size: 663 B |
Reference in new issue
Block a user