From 765b5d4c35f84c980ad7b80a16de3fe00bc6aa64 Mon Sep 17 00:00:00 2001 From: ItsJules <79675118+ItsJuls@users.noreply.github.com> Date: Sun, 14 Jul 2024 18:01:01 +0800 Subject: [PATCH 1/8] New towny marker options for towns --- .../antti/bluemaptowny/BlueMapTowny.java | 102 ++++++++++++------ .../TownyCommands/SetTownMarker.java | 69 ++++++++++++ src/main/resources/config.yml | 3 + 3 files changed, 143 insertions(+), 31 deletions(-) create mode 100644 src/main/java/codes/antti/bluemaptowny/TownyCommands/SetTownMarker.java diff --git a/src/main/java/codes/antti/bluemaptowny/BlueMapTowny.java b/src/main/java/codes/antti/bluemaptowny/BlueMapTowny.java index 4838e33..76da131 100644 --- a/src/main/java/codes/antti/bluemaptowny/BlueMapTowny.java +++ b/src/main/java/codes/antti/bluemaptowny/BlueMapTowny.java @@ -1,52 +1,51 @@ package codes.antti.bluemaptowny; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - +import codes.antti.bluemaptowny.TownyCommands.SetTownMarker; import com.flowpowered.math.vector.Vector2d; -import com.technicjelle.BMUtils.Cheese; -import de.bluecolored.bluemap.api.markers.*; -import org.apache.commons.lang.WordUtils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.Configuration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - import com.flowpowered.math.vector.Vector2i; import com.gmail.goosius.siegewar.SiegeWarAPI; import com.gmail.goosius.siegewar.enums.SiegeSide; import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; import com.palmergames.bukkit.config.ConfigNodes; -import com.palmergames.bukkit.towny.TownyAPI; -import com.palmergames.bukkit.towny.TownyEconomyHandler; -import com.palmergames.bukkit.towny.TownyFormatter; -import com.palmergames.bukkit.towny.TownySettings; +import com.palmergames.bukkit.towny.*; +import com.palmergames.bukkit.towny.object.AddonCommand; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownyObject; import com.palmergames.bukkit.towny.object.TownyWorld; import com.palmergames.bukkit.towny.utils.TownRuinUtil; +import com.technicjelle.BMUtils.Cheese; import com.technicjelle.UpdateChecker; - import de.bluecolored.bluemap.api.BlueMapAPI; +import de.bluecolored.bluemap.api.markers.Marker; +import de.bluecolored.bluemap.api.markers.MarkerSet; +import de.bluecolored.bluemap.api.markers.POIMarker; +import de.bluecolored.bluemap.api.markers.ShapeMarker; import de.bluecolored.bluemap.api.math.Color; import de.bluecolored.bluemap.api.math.Shape; +import org.apache.commons.lang.WordUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; public final class BlueMapTowny extends JavaPlugin { + + private final Map townMarkerSets = new ConcurrentHashMap<>(); private Configuration config; + public static BlueMapTowny plugin; + @Override public void onEnable() { try { @@ -61,7 +60,10 @@ public void onEnable() { reloadConfig(); saveDefaultConfig(); this.config = getConfig(); + this.plugin = this; initMarkerSets(); + registerCommands(); + makeAssetsFolder(); if (isFolia) { Bukkit.getServer().getAsyncScheduler().runAtFixedRate(this, task -> this.updateMarkers(), 1L, this.config.getLong("update-interval"), TimeUnit.SECONDS); } else { @@ -205,7 +207,8 @@ private String fillPlaceholders(String template, Town town) { flags.add("Nation: " + nation); if (TownySettings.getBoolean(ConfigNodes.TOWN_RUINING_TOWN_RUINS_ENABLED)) { String ruinedString = "Ruined: " + town.isRuined(); - if (town.isRuined()) ruinedString += " (Time left: " + (TownySettings.getTownRuinsMaxDurationHours() - TownRuinUtil.getTimeSinceRuining(town)) + " hours)"; + if (town.isRuined()) + ruinedString += " (Time left: " + (TownySettings.getTownRuinsMaxDurationHours() - TownRuinUtil.getTimeSinceRuining(town)) + " hours)"; flags.add(ruinedString); } t = t.replace("%flags%", String.join("
", flags)); @@ -222,7 +225,7 @@ private String fillPlaceholders(String template, Town town) { t = t.replace("%town_resources%", ""); } - if(getServer().getPluginManager().isPluginEnabled("SiegeWar")) { + if (getServer().getPluginManager().isPluginEnabled("SiegeWar")) { if (SiegeWarAPI.hasSiege(town)) { Siege siege = SiegeWarAPI.getSiege(town).get(); t = t.replace("%attacker%", siege.getAttackerNameForDisplay()); @@ -240,7 +243,7 @@ private String fillPlaceholders(String template, Town town) { } t = t.replace("%banner_control%", WordUtils.capitalizeFully(siege.getBannerControllingSide().name()) - + (siege.getBannerControllingSide() == SiegeSide.NOBODY ? "" : " (" + siege.getBannerControllingResidents().size() + ")")); + + (siege.getBannerControllingSide() == SiegeSide.NOBODY ? "" : " (" + siege.getBannerControllingResidents().size() + ")")); t = t.replace("%siege_status%", siege.getStatus().getName()); @@ -258,6 +261,29 @@ private String fillPlaceholders(String template, Town town) { return t; } + private String fillTownyIcons(Town town) { + String icon; + if (town.hasMeta("mapMarker")){ + switch (config.getInt("use-links-as-image-source")) { + case 1 -> { + icon = "assets/TownMarkers/" + town.getMetadata("mapMarker").getValue().toString(); + return icon; + } + case 2 -> { + icon = town.getMetadata("mapMarker").getValue().toString(); + return icon; + } + default -> { + icon = this.config.getString("style.home-icon"); + return icon; + } + } + }else{ + icon = this.config.getString("style.home-icon"); + } + return icon; + } + private void updateMarkers() { BlueMapAPI.getInstance().ifPresent((api) -> { for (World world : Bukkit.getWorlds()) { @@ -328,7 +354,7 @@ private void updateMarkers() { POIMarker iconMarker = new POIMarker.Builder() .label(townName) .detail(townDetails) - .icon(this.config.getString("style.home-icon"), 8, 8) + .icon(fillTownyIcons(town), 8, 8) .styleClasses("towny-icon") .position(spawn.get().getX(), layerY, spawn.get().getZ()) .build(); @@ -351,4 +377,18 @@ private void updateMarkers() { } }); } + + private void registerCommands(){ + if(config.getInt("use-links-as-image-source") == 1 || config.getInt("use-links-as-image-source") == 2){ + AddonCommand setTownMarker = new AddonCommand(TownyCommandAddonAPI.CommandType.TOWN_SET, "marker", new SetTownMarker()); + TownyCommandAddonAPI.addSubCommand(setTownMarker); + } + } + + private void makeAssetsFolder(){ + File file = new File(BlueMapAPI.getInstance().get().getWebApp().getWebRoot().toFile(), "/assets/TownMarkers"); + if(!file.exists()){ + file.mkdir(); + } + } } diff --git a/src/main/java/codes/antti/bluemaptowny/TownyCommands/SetTownMarker.java b/src/main/java/codes/antti/bluemaptowny/TownyCommands/SetTownMarker.java new file mode 100644 index 0000000..fc08367 --- /dev/null +++ b/src/main/java/codes/antti/bluemaptowny/TownyCommands/SetTownMarker.java @@ -0,0 +1,69 @@ +package codes.antti.bluemaptowny.TownyCommands; + +import codes.antti.bluemaptowny.BlueMapTowny; +import com.palmergames.bukkit.towny.TownyMessaging; +import com.palmergames.bukkit.towny.TownyUniverse; +import com.palmergames.bukkit.towny.object.Resident; +import com.palmergames.bukkit.towny.object.metadata.StringDataField; +import de.bluecolored.bluemap.api.BlueMapAPI; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class SetTownMarker implements CommandExecutor, TabExecutor { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (!(sender instanceof Player)) { + TownyMessaging.sendErrorMsg(sender, "Must be run by a Player!"); + return true; + } + Resident resident = TownyUniverse.getInstance().getResident(((Player) sender).getUniqueId()); + + if (!resident.hasTown()) { + TownyMessaging.sendErrorMsg(sender, "You don't have a town!"); + return true; + } + + if (!resident.isMayor() && !((Player) sender).getPlayer().hasPermission("towny.command.town.set.townmarker")) { + TownyMessaging.sendErrorMsg(sender, "You don't have permission for this or aren't the Mayor!"); + return true; + } + + TownyMessaging.sendPrefixedTownMessage(resident.getTownOrNull(), "Town Marker has been set to: " + String.join(" ", args)); + resident.getTownOrNull().addMetaData(new StringDataField("mapMarker", String.join(" ", args))); + + + return true; + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + Plugin plugin = BlueMapTowny.plugin; + switch (plugin.getConfig().getInt("use-links-as-image-source")) { + case 1 -> { + File file = new File(BlueMapAPI.getInstance().get().getWebApp().getWebRoot().toFile(), "/assets/TownMarkers"); + String[] listOfFiles = file.list(); + if (args.length == 1) { + return Arrays.stream(listOfFiles).toList(); + } + return Collections.emptyList(); + } + case 2 -> { + return Collections.singletonList(""); + } + default -> { + return Collections.emptyList(); + } + } + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8d9f95f..3b0af82 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,6 +14,9 @@ popup-siege: 'Siege: %attacker% vs %defend # If you want claims with holes in them to show up as fully claimed if only the perimeter is claimed. # This means that the map will LIE about the actual claim status of the area!!! lie-about-holes: false +# If you want to have towns have the option to use their own image markers (By default it's only a locked to 1 default image for every town) +# 0 for default, 1 as customizable within a preset of images inside a folder created by the plugin, 2 as letting the town/players choose their own town marker via a link (BE WARNED THAT YOU HAVE TO TRUST THE GOODWILL OF YOUR PLAYERS FOR THIS) +use-links-as-image-source: 0 style: # Y-level to put markers at y-level: 62 From dc4be7bf0faac906ecf5943aa1a57b82937d6993 Mon Sep 17 00:00:00 2001 From: ItsJules <79675118+ItsJuls@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:08:30 +0800 Subject: [PATCH 2/8] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b4ea3c..d24763d 100644 --- a/README.md +++ b/README.md @@ -53,12 +53,15 @@ style: fill-opacity: 0.35 # Path to icons on web or a link # Town home - home-icon-enabled: false + # If you want to have towns have the option to use their own image markers (By default it's only a locked to 1 default image for every town) + # "disabled", if you want to disable the home icon, "only-default" for default, "preset" as customizable within a preset of images inside a folder created by the plugin, "link" as letting the town/players choose their own town marker via a link (BE WARNED THAT YOU HAVE TO TRUST THE GOODWILL OF YOUR PLAYERS FOR THIS) + # Changing between the "preset" and "link" types will break existing home markers + home-icon-style: "only-default" home-icon: assets/house.png # Nation capital capital-icon-enabled: false capital-icon: assets/king.png - # Icon during war + # Icon during War war-icon-enabled: false war-icon: assets/war.png # Icon for ruined towns From 027d4b470c567667cd2d2cea6679ec06020a4d0d Mon Sep 17 00:00:00 2001 From: ItsJules <79675118+ItsJuls@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:10:50 +0800 Subject: [PATCH 3/8] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d24763d..f744c92 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,12 @@ style: | `%battle_points_defender%` | Battle points on the defender's side | | `%battle_time_left%` | Time left in the Battle Session | +### Permissions + +| Permission | Content | +|----------------------------|---------------------------------------------| +| `towny.command.town.set.townmarker` | Able to set their own Town Markers with /town set marker | + ## Building `./gradlew clean build` From 0ee5880b1168e27f7f7cf60bc5b9187cfc5f84a1 Mon Sep 17 00:00:00 2001 From: ItsJules <79675118+ItsJuls@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:34:49 +0800 Subject: [PATCH 4/8] Add files via upload --- .../TownyCommands/SetTownMarker.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/codes/antti/bluemaptowny/TownyCommands/SetTownMarker.java b/src/main/java/codes/antti/bluemaptowny/TownyCommands/SetTownMarker.java index fc08367..207f833 100644 --- a/src/main/java/codes/antti/bluemaptowny/TownyCommands/SetTownMarker.java +++ b/src/main/java/codes/antti/bluemaptowny/TownyCommands/SetTownMarker.java @@ -21,6 +21,9 @@ import java.util.List; public class SetTownMarker implements CommandExecutor, TabExecutor { + + Plugin plugin = BlueMapTowny.plugin; + @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!(sender instanceof Player)) { @@ -34,11 +37,17 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return true; } - if (!resident.isMayor() && !((Player) sender).getPlayer().hasPermission("towny.command.town.set.townmarker")) { + if (!resident.isMayor() || !((Player) sender).getPlayer().hasPermission("towny.command.town.set.townmarker")) { TownyMessaging.sendErrorMsg(sender, "You don't have permission for this or aren't the Mayor!"); return true; } + if(plugin.getConfig().getString("home-icon-style").equalsIgnoreCase("preset")){ + if(ifFileExists(String.join(" ", args)) == false){ + TownyMessaging.sendErrorMsg(resident, "This file isn't a valid file!"); + return true; + } + } TownyMessaging.sendPrefixedTownMessage(resident.getTownOrNull(), "Town Marker has been set to: " + String.join(" ", args)); resident.getTownOrNull().addMetaData(new StringDataField("mapMarker", String.join(" ", args))); @@ -48,7 +57,6 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command @Override public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - Plugin plugin = BlueMapTowny.plugin; switch (plugin.getConfig().getInt("use-links-as-image-source")) { case 1 -> { File file = new File(BlueMapAPI.getInstance().get().getWebApp().getWebRoot().toFile(), "/assets/TownMarkers"); @@ -59,11 +67,19 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return Collections.emptyList(); } case 2 -> { - return Collections.singletonList(""); + return Collections.singletonList(""); } default -> { return Collections.emptyList(); } } } + + public boolean ifFileExists(String string){ + File file = new File(BlueMapAPI.getInstance().get().getWebApp().getWebRoot().toFile(), "/assets/townmarkers/" + string); + if(file.isFile()) { + return true; + } + return false; + } } From 715ff22f8ea1b0b11d571452f803440b0143b562 Mon Sep 17 00:00:00 2001 From: ItsJules <79675118+ItsJuls@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:35:12 +0800 Subject: [PATCH 5/8] Add files via upload --- src/main/resources/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3b0af82..6dbdb83 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,9 +14,6 @@ popup-siege: 'Siege: %attacker% vs %defend # If you want claims with holes in them to show up as fully claimed if only the perimeter is claimed. # This means that the map will LIE about the actual claim status of the area!!! lie-about-holes: false -# If you want to have towns have the option to use their own image markers (By default it's only a locked to 1 default image for every town) -# 0 for default, 1 as customizable within a preset of images inside a folder created by the plugin, 2 as letting the town/players choose their own town marker via a link (BE WARNED THAT YOU HAVE TO TRUST THE GOODWILL OF YOUR PLAYERS FOR THIS) -use-links-as-image-source: 0 style: # Y-level to put markers at y-level: 62 @@ -29,7 +26,10 @@ style: fill-opacity: 0.35 # Path to icons on web or a link # Town home - home-icon-enabled: false + # If you want to have towns have the option to use their own image markers (By default it's only a locked to 1 default image for every town) + # "disabled", if you want to disable the home icon, "only-default" for default, "preset" as customizable within a preset of images inside a folder created by the plugin, "link" as letting the town/players choose their own town marker via a link (BE WARNED THAT YOU HAVE TO TRUST THE GOODWILL OF YOUR PLAYERS FOR THIS) + # Changing between the "preset" and "link" types will break existing home markers + home-icon-style: "only-default" home-icon: assets/house.png # Nation capital capital-icon-enabled: false From 6d822f215bcfd025ae7f62b29900103e2b523621 Mon Sep 17 00:00:00 2001 From: ItsJules <79675118+ItsJuls@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:35:40 +0800 Subject: [PATCH 6/8] Add files via upload --- .../TownyCommands/BlueMapTowny.java | 397 ++++++++++++++++++ 1 file changed, 397 insertions(+) create mode 100644 src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java diff --git a/src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java b/src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java new file mode 100644 index 0000000..dacb805 --- /dev/null +++ b/src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java @@ -0,0 +1,397 @@ +package codes.antti.bluemaptowny; + +import codes.antti.bluemaptowny.TownyCommands.SetTownMarker; +import com.flowpowered.math.vector.Vector2d; +import com.flowpowered.math.vector.Vector2i; +import com.gmail.goosius.siegewar.SiegeWarAPI; +import com.gmail.goosius.siegewar.enums.SiegeSide; +import com.gmail.goosius.siegewar.objects.Siege; +import com.gmail.goosius.siegewar.settings.SiegeWarSettings; +import com.palmergames.bukkit.config.ConfigNodes; +import com.palmergames.bukkit.towny.*; +import com.palmergames.bukkit.towny.object.AddonCommand; +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.TownyObject; +import com.palmergames.bukkit.towny.object.TownyWorld; +import com.palmergames.bukkit.towny.utils.TownRuinUtil; +import com.technicjelle.BMUtils.Cheese; +import com.technicjelle.UpdateChecker; +import de.bluecolored.bluemap.api.BlueMapAPI; +import de.bluecolored.bluemap.api.markers.Marker; +import de.bluecolored.bluemap.api.markers.MarkerSet; +import de.bluecolored.bluemap.api.markers.POIMarker; +import de.bluecolored.bluemap.api.markers.ShapeMarker; +import de.bluecolored.bluemap.api.math.Color; +import de.bluecolored.bluemap.api.math.Shape; +import org.apache.commons.lang.WordUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +public final class BlueMapTowny extends JavaPlugin { + + + private final Map townMarkerSets = new ConcurrentHashMap<>(); + private Configuration config; + + public static BlueMapTowny plugin; + + @Override + public void onEnable() { + try { + UpdateChecker updateChecker = new UpdateChecker("Chicken", "BlueMap-Towny", getDescription().getVersion()); + updateChecker.check(); + updateChecker.logUpdateMessage(getLogger()); + } catch (IOException e) { + e.printStackTrace(); + } + boolean isFolia = isFolia(); + BlueMapAPI.onEnable((api) -> { + reloadConfig(); + saveDefaultConfig(); + this.config = getConfig(); + this.plugin = this; + initMarkerSets(); + registerCommands(); + makeAssetsFolder(); + if (isFolia) { + Bukkit.getServer().getAsyncScheduler().runAtFixedRate(this, task -> this.updateMarkers(), 1L, this.config.getLong("update-interval"), TimeUnit.SECONDS); + } else { + Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::updateMarkers, 0L, this.config.getLong("update-interval") * 20); + } + }); + BlueMapAPI.onDisable((api) -> { + if (isFolia) { + Bukkit.getServer().getGlobalRegionScheduler().cancelTasks(this); + } else { + Bukkit.getScheduler().cancelTasks(this); + } + }); + } + + private static boolean isFolia() { + try { + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); + return true; + } catch (ClassNotFoundException e) { + return false; + } + } + + private void initMarkerSets() { + BlueMapAPI.getInstance().ifPresent((api) -> { + townMarkerSets.clear(); + for (World world : Bukkit.getWorlds()) { + api.getWorld(world).ifPresent((bmWorld) -> { + MarkerSet set = new MarkerSet("Towns"); + townMarkerSets.put(world.getUID(), set); + bmWorld.getMaps().forEach((map) -> { + map.getMarkerSets().put("towny", set); + }); + }); + } + }); + } + + private Color getFillColor(Town town) { + String opacity = String.format("%02X", (int) (this.config.getDouble("style.fill-opacity") * 255)); + + if (this.config.getBoolean("dynamic-town-colors")) { + String hex = town.getMapColorHexCode(); + if (hex != null && !hex.equals("")) { + return new Color("#" + hex + opacity); + } + } + + if (this.config.getBoolean("dynamic-nation-colors")) { + String hex = town.getNationMapColorHexCode(); + if (hex != null && !hex.equals("")) { + return new Color("#" + hex + opacity); + } + } + + return new Color(this.config.getString("style.fill-color") + opacity); + } + + private Color getLineColor(Town town) { + String opacity = String.format("%02X", (int) (this.config.getDouble("style.border-opacity") * 255)); + + if (this.config.getBoolean("dynamic-nation-colors")) { + String hex = town.getNationMapColorHexCode(); + if (hex != null && !hex.equals("")) { + return new Color("#" + hex + opacity); + } + } + + if (this.config.getBoolean("dynamic-town-colors")) { + String hex = town.getMapColorHexCode(); + if (hex != null && !hex.equals("")) { + return new Color("#" + hex + opacity); + } + } + + return new Color(this.config.getString("style.border-color") + opacity); + } + + private String fillPlaceholders(String template, Town town) { + String t = template; + + t = t.replace("%name%", town.getName()); + + t = t.replace("%mayor%", town.hasMayor() ? town.getMayor().getName() : ""); + + String[] residents = town.getResidents().stream().map(TownyObject::getName).toArray(String[]::new); + if (residents.length > 34) { + String[] old = residents; + residents = new String[35 + 1]; + System.arraycopy(old, 0, residents, 0, 35); + residents[35] = "and more..."; + } + t = t.replace("%residents%", String.join(", ", residents)); + + String[] residentsDisplay = town.getResidents().stream().map((r) -> { + Player p = Bukkit.getPlayer(r.getName()); + if (p == null) return r.getFormattedName(); + return p.getDisplayName(); + }).toArray(String[]::new); + if (residentsDisplay.length > 34) { + String[] old = residentsDisplay; + residentsDisplay = new String[35 + 1]; + System.arraycopy(old, 0, residentsDisplay, 0, 35); + residentsDisplay[35] = "and more..."; + } + t = t.replace("%residentdisplaynames%", String.join(", ", residentsDisplay)); + + t = t.replace("%assistants%", String.join(", ", town.getRank("assistant").stream().map(TownyObject::getName).toArray(String[]::new))); + + t = t.replace("%residentcount%", "" + town.getResidents().size()); + + t = t.replace("%founded%", town.getRegistered() != 0 ? TownyFormatter.registeredFormat.format(town.getRegistered()) : "None"); + + t = t.replace("%board%", town.getBoard()); + + t = t.replace("%trusted%", town.getTrustedResidents().isEmpty() ? "None" : town.getTrustedResidents().stream().map(TownyObject::getName).collect(Collectors.joining(", "))); + + if (TownySettings.isUsingEconomy() && TownyEconomyHandler.isActive()) { + if (town.isTaxPercentage()) t = t.replace("%tax%", town.getTaxes() + "%"); + else t = t.replace("%tax%", TownyEconomyHandler.getFormattedBalance(town.getTaxes())); + t = t.replace("%bank%", TownyEconomyHandler.getFormattedBalance(town.getAccount().getCachedBalance())); + } + + String nation = town.hasNation() ? Objects.requireNonNull(town.getNationOrNull()).getName() : ""; + t = t.replace("%nation%", nation); + t = t.replace("%nationstatus%", town.hasNation() ? (town.isCapital() ? "Capital of " + nation : "Member of " + nation) : ""); + + t = t.replace("%public%", town.isPublic() ? "true" : "false"); + + t = t.replace("%peaceful%", town.isNeutral() ? "true" : "false"); + + t = t.replace("%war%", town.hasActiveWar() ? "true" : "false"); + + List flags = new ArrayList<>(); + flags.add("Has Upkeep: " + town.hasUpkeep()); + flags.add("PvP: " + town.isPVP()); + flags.add("Mobs: " + town.hasMobs()); + flags.add("Explosion: " + town.isExplosion()); + flags.add("Fire: " + town.isFire()); + flags.add("Nation: " + nation); + if (TownySettings.getBoolean(ConfigNodes.TOWN_RUINING_TOWN_RUINS_ENABLED)) { + String ruinedString = "Ruined: " + town.isRuined(); + if (town.isRuined()) + ruinedString += " (Time left: " + (TownySettings.getTownRuinsMaxDurationHours() - TownRuinUtil.getTimeSinceRuining(town)) + " hours)"; + flags.add(ruinedString); + } + t = t.replace("%flags%", String.join("
", flags)); + + if (town.hasMeta("townycultures_culture")) { + t = t.replace("%town_culture%", Objects.requireNonNull(town.getMetadata("townycultures_culture")).getValue().toString()); + } else { + t = t.replace("%town_culture%", ""); + } + + if (town.hasMeta("townyresources_dailyproduction")) { + t = t.replace("%town_resources%", Objects.requireNonNull(town.getMetadata("townyresources_dailyproduction")).getValue().toString()); + } else { + t = t.replace("%town_resources%", ""); + } + + if (getServer().getPluginManager().isPluginEnabled("SiegeWar")) { + if (SiegeWarAPI.hasSiege(town)) { + Siege siege = SiegeWarAPI.getSiege(town).get(); + t = t.replace("%attacker%", siege.getAttackerNameForDisplay()); + + t = t.replace("%defender%", siege.getDefenderNameForDisplay()); + + t = t.replace("%siege_type%", siege.getSiegeType().getName()); + + t = t.replace("%sessions_completed%", String.valueOf(siege.getNumBattleSessionsCompleted())); + + t = t.replace("%sessions_total%", String.valueOf(SiegeWarSettings.getSiegeDurationBattleSessions())); + + if (TownyEconomyHandler.isActive()) { + t = t.replace("%war_chest%", TownyEconomyHandler.getFormattedBalance(siege.getWarChestAmount())); + } + + t = t.replace("%banner_control%", WordUtils.capitalizeFully(siege.getBannerControllingSide().name()) + + (siege.getBannerControllingSide() == SiegeSide.NOBODY ? "" : " (" + siege.getBannerControllingResidents().size() + ")")); + + t = t.replace("%siege_status%", siege.getStatus().getName()); + + t = t.replace("%siege_balance%", siege.getSiegeBalance().toString()); + + t = t.replace("%battle_points_attacker%", siege.getFormattedAttackerBattlePoints()); + + t = t.replace("%battle_points_defender%", siege.getFormattedDefenderBattlePoints()); + + t = t.replace("%battle_time_left%", siege.getFormattedBattleTimeRemaining()); + + } + } + + return t; + } + + private String fillTownyIcons(Town town) { + String icon; + if (town.hasMeta("mapMarker")){ + switch (config.getString("home-icon-style")) { + case "preset" -> { + icon = "assets/townmarkers/" + town.getMetadata("mapMarker").getValue().toString(); + return icon; + } + case "link" -> { + icon = town.getMetadata("mapMarker").getValue().toString(); + return icon; + } + default -> { + icon = this.config.getString("style.home-icon"); + return icon; + } + } + }else{ + icon = this.config.getString("style.home-icon"); + } + return icon; + } + + private void updateMarkers() { + BlueMapAPI.getInstance().ifPresent((api) -> { + for (World world : Bukkit.getWorlds()) { + if (api.getWorld(world.getName()).isEmpty()) continue; + MarkerSet set = townMarkerSets.get(world.getUID()); + if (set == null) continue; + Map markers = set.getMarkers(); + markers.clear(); + TownyWorld townyworld = TownyAPI.getInstance().getTownyWorld(world); + if (townyworld == null) continue; + TownyAPI.getInstance().getTowns().forEach((town) -> { + Vector2i[] chunks = town.getTownBlocks().stream().filter((tb) -> tb.getWorld().equals(townyworld)).map((tb) -> new Vector2i(tb.getX(), tb.getZ())).toArray(Vector2i[]::new); + int townSize = TownySettings.getTownBlockSize(); + Vector2d cellSize = new Vector2d(townSize, townSize); + Collection cheeses = Cheese.createPlatterFromCells(cellSize, chunks); + double layerY = this.config.getDouble("style.y-level"); + String townName = town.getName(); + String townDetails = fillPlaceholders(this.config.getString("popup"), town); + String siegeDetails = fillPlaceholders(this.config.getString("popup-siege"), town); + int seq = 0; + for (Cheese cheese : cheeses) { + ShapeMarker.Builder chunkMarkerBuilder = new ShapeMarker.Builder() + .label(townName) + .detail(townDetails) + .lineColor(getLineColor(town)) + .lineWidth(this.config.getInt("style.border-width")) + .fillColor(getFillColor(town)) + .depthTestEnabled(false) + .shape(cheese.getShape(), (float) layerY); + if (this.config.getBoolean("lie-about-holes", false) == false) chunkMarkerBuilder.holes(cheese.getHoles().toArray(Shape[]::new)); + ShapeMarker chunkMarker = chunkMarkerBuilder + .centerPosition() + .build(); + markers.put("towny." + townName + ".area." + seq, chunkMarker); + seq += 1; + } + Optional spawn = Optional.ofNullable(town.getSpawnOrNull()); + if (spawn.isPresent() && spawn.get().getWorld().equals(world)) { + if (this.config.getBoolean("style.ruined-icon-enabled") && town.isRuined()) { + POIMarker iconMarker = new POIMarker.Builder() + .label(townName) + .detail(townDetails) + .icon(this.config.getString("style.ruined-icon"), 8, 8) + .styleClasses("towny-icon") + .position(spawn.get().getX(), layerY, spawn.get().getZ()) + .build(); + markers.put("towny." + townName + ".icon", iconMarker); + } else if (this.config.getBoolean("style.war-icon-enabled") && town.hasActiveWar()) { + POIMarker iconMarker = new POIMarker.Builder() + .label(townName) + .detail(townDetails) + .icon(this.config.getString("style.war-icon"), 8, 8) + .styleClasses("towny-icon") + .position(spawn.get().getX(), layerY, spawn.get().getZ()) + .build(); + markers.put("towny." + townName + ".icon", iconMarker); + } else if (this.config.getBoolean("style.capital-icon-enabled") && town.isCapital()) { + POIMarker iconMarker = new POIMarker.Builder() + .label(townName) + .detail(townDetails) + .icon(this.config.getString("style.capital-icon"), 8, 8) + .styleClasses("towny-icon") + .position(spawn.get().getX(), layerY, spawn.get().getZ()) + .build(); + + markers.put("towny." + townName + ".icon", iconMarker); + } else if (!this.config.getString("style.home-icon-style").equalsIgnoreCase("disabled")) { + POIMarker iconMarker = new POIMarker.Builder() + .label(townName) + .detail(townDetails) + .icon(fillTownyIcons(town), 8, 8) + .styleClasses("towny-icon") + .position(spawn.get().getX(), layerY, spawn.get().getZ()) + .build(); + markers.put("towny." + townName + ".icon", iconMarker); + } + } + + if (getServer().getPluginManager().isPluginEnabled("SiegeWar") && this.config.getBoolean("style.war-icon-enabled") && SiegeWarAPI.hasActiveSiege(town)) { + Location flagLoc = SiegeWarAPI.getSiege(town).get().getFlagLocation(); + POIMarker iconMarker = new POIMarker.Builder() + .label(townName) + .detail(siegeDetails) + .icon(this.config.getString("style.war-icon"), 8, 8) + .styleClasses("towny-icon") + .position(flagLoc.getX(), layerY, flagLoc.getZ()) + .build(); + markers.put("towny." + townName + ".siege", iconMarker); + } + }); + } + }); + } + + private void registerCommands(){ + AddonCommand setTownMarker = new AddonCommand(TownyCommandAddonAPI.CommandType.TOWN_SET, "marker", new SetTownMarker()); + if(config.getString("home-icon-style").equalsIgnoreCase("preset")|| config.getString("home-icon-style").equalsIgnoreCase("link")){ + TownyCommandAddonAPI.addSubCommand(setTownMarker); + }else{ + TownyCommandAddonAPI.removeSubCommand(setTownMarker); + } + + } + + private void makeAssetsFolder(){ + File file = new File(BlueMapAPI.getInstance().get().getWebApp().getWebRoot().toFile(), "/assets/townmarkers"); + if(!file.exists()){ + file.mkdir(); + } + } +} From 23434cca6220efb38f37233733afbe9e7c04a542 Mon Sep 17 00:00:00 2001 From: ItsJules <79675118+ItsJuls@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:40:32 +0800 Subject: [PATCH 7/8] Delete src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java --- .../TownyCommands/BlueMapTowny.java | 397 ------------------ 1 file changed, 397 deletions(-) delete mode 100644 src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java diff --git a/src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java b/src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java deleted file mode 100644 index dacb805..0000000 --- a/src/main/java/codes/antti/bluemaptowny/TownyCommands/BlueMapTowny.java +++ /dev/null @@ -1,397 +0,0 @@ -package codes.antti.bluemaptowny; - -import codes.antti.bluemaptowny.TownyCommands.SetTownMarker; -import com.flowpowered.math.vector.Vector2d; -import com.flowpowered.math.vector.Vector2i; -import com.gmail.goosius.siegewar.SiegeWarAPI; -import com.gmail.goosius.siegewar.enums.SiegeSide; -import com.gmail.goosius.siegewar.objects.Siege; -import com.gmail.goosius.siegewar.settings.SiegeWarSettings; -import com.palmergames.bukkit.config.ConfigNodes; -import com.palmergames.bukkit.towny.*; -import com.palmergames.bukkit.towny.object.AddonCommand; -import com.palmergames.bukkit.towny.object.Town; -import com.palmergames.bukkit.towny.object.TownyObject; -import com.palmergames.bukkit.towny.object.TownyWorld; -import com.palmergames.bukkit.towny.utils.TownRuinUtil; -import com.technicjelle.BMUtils.Cheese; -import com.technicjelle.UpdateChecker; -import de.bluecolored.bluemap.api.BlueMapAPI; -import de.bluecolored.bluemap.api.markers.Marker; -import de.bluecolored.bluemap.api.markers.MarkerSet; -import de.bluecolored.bluemap.api.markers.POIMarker; -import de.bluecolored.bluemap.api.markers.ShapeMarker; -import de.bluecolored.bluemap.api.math.Color; -import de.bluecolored.bluemap.api.math.Shape; -import org.apache.commons.lang.WordUtils; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.Configuration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.io.File; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -public final class BlueMapTowny extends JavaPlugin { - - - private final Map townMarkerSets = new ConcurrentHashMap<>(); - private Configuration config; - - public static BlueMapTowny plugin; - - @Override - public void onEnable() { - try { - UpdateChecker updateChecker = new UpdateChecker("Chicken", "BlueMap-Towny", getDescription().getVersion()); - updateChecker.check(); - updateChecker.logUpdateMessage(getLogger()); - } catch (IOException e) { - e.printStackTrace(); - } - boolean isFolia = isFolia(); - BlueMapAPI.onEnable((api) -> { - reloadConfig(); - saveDefaultConfig(); - this.config = getConfig(); - this.plugin = this; - initMarkerSets(); - registerCommands(); - makeAssetsFolder(); - if (isFolia) { - Bukkit.getServer().getAsyncScheduler().runAtFixedRate(this, task -> this.updateMarkers(), 1L, this.config.getLong("update-interval"), TimeUnit.SECONDS); - } else { - Bukkit.getScheduler().runTaskTimerAsynchronously(this, this::updateMarkers, 0L, this.config.getLong("update-interval") * 20); - } - }); - BlueMapAPI.onDisable((api) -> { - if (isFolia) { - Bukkit.getServer().getGlobalRegionScheduler().cancelTasks(this); - } else { - Bukkit.getScheduler().cancelTasks(this); - } - }); - } - - private static boolean isFolia() { - try { - Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); - return true; - } catch (ClassNotFoundException e) { - return false; - } - } - - private void initMarkerSets() { - BlueMapAPI.getInstance().ifPresent((api) -> { - townMarkerSets.clear(); - for (World world : Bukkit.getWorlds()) { - api.getWorld(world).ifPresent((bmWorld) -> { - MarkerSet set = new MarkerSet("Towns"); - townMarkerSets.put(world.getUID(), set); - bmWorld.getMaps().forEach((map) -> { - map.getMarkerSets().put("towny", set); - }); - }); - } - }); - } - - private Color getFillColor(Town town) { - String opacity = String.format("%02X", (int) (this.config.getDouble("style.fill-opacity") * 255)); - - if (this.config.getBoolean("dynamic-town-colors")) { - String hex = town.getMapColorHexCode(); - if (hex != null && !hex.equals("")) { - return new Color("#" + hex + opacity); - } - } - - if (this.config.getBoolean("dynamic-nation-colors")) { - String hex = town.getNationMapColorHexCode(); - if (hex != null && !hex.equals("")) { - return new Color("#" + hex + opacity); - } - } - - return new Color(this.config.getString("style.fill-color") + opacity); - } - - private Color getLineColor(Town town) { - String opacity = String.format("%02X", (int) (this.config.getDouble("style.border-opacity") * 255)); - - if (this.config.getBoolean("dynamic-nation-colors")) { - String hex = town.getNationMapColorHexCode(); - if (hex != null && !hex.equals("")) { - return new Color("#" + hex + opacity); - } - } - - if (this.config.getBoolean("dynamic-town-colors")) { - String hex = town.getMapColorHexCode(); - if (hex != null && !hex.equals("")) { - return new Color("#" + hex + opacity); - } - } - - return new Color(this.config.getString("style.border-color") + opacity); - } - - private String fillPlaceholders(String template, Town town) { - String t = template; - - t = t.replace("%name%", town.getName()); - - t = t.replace("%mayor%", town.hasMayor() ? town.getMayor().getName() : ""); - - String[] residents = town.getResidents().stream().map(TownyObject::getName).toArray(String[]::new); - if (residents.length > 34) { - String[] old = residents; - residents = new String[35 + 1]; - System.arraycopy(old, 0, residents, 0, 35); - residents[35] = "and more..."; - } - t = t.replace("%residents%", String.join(", ", residents)); - - String[] residentsDisplay = town.getResidents().stream().map((r) -> { - Player p = Bukkit.getPlayer(r.getName()); - if (p == null) return r.getFormattedName(); - return p.getDisplayName(); - }).toArray(String[]::new); - if (residentsDisplay.length > 34) { - String[] old = residentsDisplay; - residentsDisplay = new String[35 + 1]; - System.arraycopy(old, 0, residentsDisplay, 0, 35); - residentsDisplay[35] = "and more..."; - } - t = t.replace("%residentdisplaynames%", String.join(", ", residentsDisplay)); - - t = t.replace("%assistants%", String.join(", ", town.getRank("assistant").stream().map(TownyObject::getName).toArray(String[]::new))); - - t = t.replace("%residentcount%", "" + town.getResidents().size()); - - t = t.replace("%founded%", town.getRegistered() != 0 ? TownyFormatter.registeredFormat.format(town.getRegistered()) : "None"); - - t = t.replace("%board%", town.getBoard()); - - t = t.replace("%trusted%", town.getTrustedResidents().isEmpty() ? "None" : town.getTrustedResidents().stream().map(TownyObject::getName).collect(Collectors.joining(", "))); - - if (TownySettings.isUsingEconomy() && TownyEconomyHandler.isActive()) { - if (town.isTaxPercentage()) t = t.replace("%tax%", town.getTaxes() + "%"); - else t = t.replace("%tax%", TownyEconomyHandler.getFormattedBalance(town.getTaxes())); - t = t.replace("%bank%", TownyEconomyHandler.getFormattedBalance(town.getAccount().getCachedBalance())); - } - - String nation = town.hasNation() ? Objects.requireNonNull(town.getNationOrNull()).getName() : ""; - t = t.replace("%nation%", nation); - t = t.replace("%nationstatus%", town.hasNation() ? (town.isCapital() ? "Capital of " + nation : "Member of " + nation) : ""); - - t = t.replace("%public%", town.isPublic() ? "true" : "false"); - - t = t.replace("%peaceful%", town.isNeutral() ? "true" : "false"); - - t = t.replace("%war%", town.hasActiveWar() ? "true" : "false"); - - List flags = new ArrayList<>(); - flags.add("Has Upkeep: " + town.hasUpkeep()); - flags.add("PvP: " + town.isPVP()); - flags.add("Mobs: " + town.hasMobs()); - flags.add("Explosion: " + town.isExplosion()); - flags.add("Fire: " + town.isFire()); - flags.add("Nation: " + nation); - if (TownySettings.getBoolean(ConfigNodes.TOWN_RUINING_TOWN_RUINS_ENABLED)) { - String ruinedString = "Ruined: " + town.isRuined(); - if (town.isRuined()) - ruinedString += " (Time left: " + (TownySettings.getTownRuinsMaxDurationHours() - TownRuinUtil.getTimeSinceRuining(town)) + " hours)"; - flags.add(ruinedString); - } - t = t.replace("%flags%", String.join("
", flags)); - - if (town.hasMeta("townycultures_culture")) { - t = t.replace("%town_culture%", Objects.requireNonNull(town.getMetadata("townycultures_culture")).getValue().toString()); - } else { - t = t.replace("%town_culture%", ""); - } - - if (town.hasMeta("townyresources_dailyproduction")) { - t = t.replace("%town_resources%", Objects.requireNonNull(town.getMetadata("townyresources_dailyproduction")).getValue().toString()); - } else { - t = t.replace("%town_resources%", ""); - } - - if (getServer().getPluginManager().isPluginEnabled("SiegeWar")) { - if (SiegeWarAPI.hasSiege(town)) { - Siege siege = SiegeWarAPI.getSiege(town).get(); - t = t.replace("%attacker%", siege.getAttackerNameForDisplay()); - - t = t.replace("%defender%", siege.getDefenderNameForDisplay()); - - t = t.replace("%siege_type%", siege.getSiegeType().getName()); - - t = t.replace("%sessions_completed%", String.valueOf(siege.getNumBattleSessionsCompleted())); - - t = t.replace("%sessions_total%", String.valueOf(SiegeWarSettings.getSiegeDurationBattleSessions())); - - if (TownyEconomyHandler.isActive()) { - t = t.replace("%war_chest%", TownyEconomyHandler.getFormattedBalance(siege.getWarChestAmount())); - } - - t = t.replace("%banner_control%", WordUtils.capitalizeFully(siege.getBannerControllingSide().name()) - + (siege.getBannerControllingSide() == SiegeSide.NOBODY ? "" : " (" + siege.getBannerControllingResidents().size() + ")")); - - t = t.replace("%siege_status%", siege.getStatus().getName()); - - t = t.replace("%siege_balance%", siege.getSiegeBalance().toString()); - - t = t.replace("%battle_points_attacker%", siege.getFormattedAttackerBattlePoints()); - - t = t.replace("%battle_points_defender%", siege.getFormattedDefenderBattlePoints()); - - t = t.replace("%battle_time_left%", siege.getFormattedBattleTimeRemaining()); - - } - } - - return t; - } - - private String fillTownyIcons(Town town) { - String icon; - if (town.hasMeta("mapMarker")){ - switch (config.getString("home-icon-style")) { - case "preset" -> { - icon = "assets/townmarkers/" + town.getMetadata("mapMarker").getValue().toString(); - return icon; - } - case "link" -> { - icon = town.getMetadata("mapMarker").getValue().toString(); - return icon; - } - default -> { - icon = this.config.getString("style.home-icon"); - return icon; - } - } - }else{ - icon = this.config.getString("style.home-icon"); - } - return icon; - } - - private void updateMarkers() { - BlueMapAPI.getInstance().ifPresent((api) -> { - for (World world : Bukkit.getWorlds()) { - if (api.getWorld(world.getName()).isEmpty()) continue; - MarkerSet set = townMarkerSets.get(world.getUID()); - if (set == null) continue; - Map markers = set.getMarkers(); - markers.clear(); - TownyWorld townyworld = TownyAPI.getInstance().getTownyWorld(world); - if (townyworld == null) continue; - TownyAPI.getInstance().getTowns().forEach((town) -> { - Vector2i[] chunks = town.getTownBlocks().stream().filter((tb) -> tb.getWorld().equals(townyworld)).map((tb) -> new Vector2i(tb.getX(), tb.getZ())).toArray(Vector2i[]::new); - int townSize = TownySettings.getTownBlockSize(); - Vector2d cellSize = new Vector2d(townSize, townSize); - Collection cheeses = Cheese.createPlatterFromCells(cellSize, chunks); - double layerY = this.config.getDouble("style.y-level"); - String townName = town.getName(); - String townDetails = fillPlaceholders(this.config.getString("popup"), town); - String siegeDetails = fillPlaceholders(this.config.getString("popup-siege"), town); - int seq = 0; - for (Cheese cheese : cheeses) { - ShapeMarker.Builder chunkMarkerBuilder = new ShapeMarker.Builder() - .label(townName) - .detail(townDetails) - .lineColor(getLineColor(town)) - .lineWidth(this.config.getInt("style.border-width")) - .fillColor(getFillColor(town)) - .depthTestEnabled(false) - .shape(cheese.getShape(), (float) layerY); - if (this.config.getBoolean("lie-about-holes", false) == false) chunkMarkerBuilder.holes(cheese.getHoles().toArray(Shape[]::new)); - ShapeMarker chunkMarker = chunkMarkerBuilder - .centerPosition() - .build(); - markers.put("towny." + townName + ".area." + seq, chunkMarker); - seq += 1; - } - Optional spawn = Optional.ofNullable(town.getSpawnOrNull()); - if (spawn.isPresent() && spawn.get().getWorld().equals(world)) { - if (this.config.getBoolean("style.ruined-icon-enabled") && town.isRuined()) { - POIMarker iconMarker = new POIMarker.Builder() - .label(townName) - .detail(townDetails) - .icon(this.config.getString("style.ruined-icon"), 8, 8) - .styleClasses("towny-icon") - .position(spawn.get().getX(), layerY, spawn.get().getZ()) - .build(); - markers.put("towny." + townName + ".icon", iconMarker); - } else if (this.config.getBoolean("style.war-icon-enabled") && town.hasActiveWar()) { - POIMarker iconMarker = new POIMarker.Builder() - .label(townName) - .detail(townDetails) - .icon(this.config.getString("style.war-icon"), 8, 8) - .styleClasses("towny-icon") - .position(spawn.get().getX(), layerY, spawn.get().getZ()) - .build(); - markers.put("towny." + townName + ".icon", iconMarker); - } else if (this.config.getBoolean("style.capital-icon-enabled") && town.isCapital()) { - POIMarker iconMarker = new POIMarker.Builder() - .label(townName) - .detail(townDetails) - .icon(this.config.getString("style.capital-icon"), 8, 8) - .styleClasses("towny-icon") - .position(spawn.get().getX(), layerY, spawn.get().getZ()) - .build(); - - markers.put("towny." + townName + ".icon", iconMarker); - } else if (!this.config.getString("style.home-icon-style").equalsIgnoreCase("disabled")) { - POIMarker iconMarker = new POIMarker.Builder() - .label(townName) - .detail(townDetails) - .icon(fillTownyIcons(town), 8, 8) - .styleClasses("towny-icon") - .position(spawn.get().getX(), layerY, spawn.get().getZ()) - .build(); - markers.put("towny." + townName + ".icon", iconMarker); - } - } - - if (getServer().getPluginManager().isPluginEnabled("SiegeWar") && this.config.getBoolean("style.war-icon-enabled") && SiegeWarAPI.hasActiveSiege(town)) { - Location flagLoc = SiegeWarAPI.getSiege(town).get().getFlagLocation(); - POIMarker iconMarker = new POIMarker.Builder() - .label(townName) - .detail(siegeDetails) - .icon(this.config.getString("style.war-icon"), 8, 8) - .styleClasses("towny-icon") - .position(flagLoc.getX(), layerY, flagLoc.getZ()) - .build(); - markers.put("towny." + townName + ".siege", iconMarker); - } - }); - } - }); - } - - private void registerCommands(){ - AddonCommand setTownMarker = new AddonCommand(TownyCommandAddonAPI.CommandType.TOWN_SET, "marker", new SetTownMarker()); - if(config.getString("home-icon-style").equalsIgnoreCase("preset")|| config.getString("home-icon-style").equalsIgnoreCase("link")){ - TownyCommandAddonAPI.addSubCommand(setTownMarker); - }else{ - TownyCommandAddonAPI.removeSubCommand(setTownMarker); - } - - } - - private void makeAssetsFolder(){ - File file = new File(BlueMapAPI.getInstance().get().getWebApp().getWebRoot().toFile(), "/assets/townmarkers"); - if(!file.exists()){ - file.mkdir(); - } - } -} From 87df0e936663d9690926f7f5e26ca10b1be9632b Mon Sep 17 00:00:00 2001 From: ItsJules <79675118+ItsJuls@users.noreply.github.com> Date: Sat, 3 Aug 2024 19:41:15 +0800 Subject: [PATCH 8/8] fixed bluemaptowny not being in its location XD --- .../antti/bluemaptowny/BlueMapTowny.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/codes/antti/bluemaptowny/BlueMapTowny.java b/src/main/java/codes/antti/bluemaptowny/BlueMapTowny.java index 76da131..dacb805 100644 --- a/src/main/java/codes/antti/bluemaptowny/BlueMapTowny.java +++ b/src/main/java/codes/antti/bluemaptowny/BlueMapTowny.java @@ -264,12 +264,12 @@ private String fillPlaceholders(String template, Town town) { private String fillTownyIcons(Town town) { String icon; if (town.hasMeta("mapMarker")){ - switch (config.getInt("use-links-as-image-source")) { - case 1 -> { - icon = "assets/TownMarkers/" + town.getMetadata("mapMarker").getValue().toString(); + switch (config.getString("home-icon-style")) { + case "preset" -> { + icon = "assets/townmarkers/" + town.getMetadata("mapMarker").getValue().toString(); return icon; } - case 2 -> { + case "link" -> { icon = town.getMetadata("mapMarker").getValue().toString(); return icon; } @@ -350,7 +350,7 @@ private void updateMarkers() { .build(); markers.put("towny." + townName + ".icon", iconMarker); - } else if (this.config.getBoolean("style.home-icon-enabled")) { + } else if (!this.config.getString("style.home-icon-style").equalsIgnoreCase("disabled")) { POIMarker iconMarker = new POIMarker.Builder() .label(townName) .detail(townDetails) @@ -379,14 +379,17 @@ private void updateMarkers() { } private void registerCommands(){ - if(config.getInt("use-links-as-image-source") == 1 || config.getInt("use-links-as-image-source") == 2){ - AddonCommand setTownMarker = new AddonCommand(TownyCommandAddonAPI.CommandType.TOWN_SET, "marker", new SetTownMarker()); + AddonCommand setTownMarker = new AddonCommand(TownyCommandAddonAPI.CommandType.TOWN_SET, "marker", new SetTownMarker()); + if(config.getString("home-icon-style").equalsIgnoreCase("preset")|| config.getString("home-icon-style").equalsIgnoreCase("link")){ TownyCommandAddonAPI.addSubCommand(setTownMarker); + }else{ + TownyCommandAddonAPI.removeSubCommand(setTownMarker); } + } private void makeAssetsFolder(){ - File file = new File(BlueMapAPI.getInstance().get().getWebApp().getWebRoot().toFile(), "/assets/TownMarkers"); + File file = new File(BlueMapAPI.getInstance().get().getWebApp().getWebRoot().toFile(), "/assets/townmarkers"); if(!file.exists()){ file.mkdir(); }