Add pl3xmap

This commit is contained in:
destro174 2022-02-15 15:26:23 +01:00
parent ca71243ad5
commit c17fb9cd5f
7 changed files with 299 additions and 1 deletions

10
pom.xml
View File

@ -55,6 +55,10 @@
<name>Altitude Maven Repo</name>
<url>https://repo.destro.xyz/snapshots</url>
</repository>
<repository> <!-- Pl3xMap -->
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<build>
@ -202,6 +206,12 @@
<artifactId>mypet</artifactId>
<version>3.11-SNAPSHOT</version>
</dependency>
<!-- Pl3xMap -->
<dependency>
<groupId>com.github.NeumimTo</groupId>
<artifactId>Pl3xMap</artifactId>
<version>1.18-2</version>
</dependency>
</dependencies>
<distributionManagement>

View File

@ -24,6 +24,7 @@ import me.ryanhamshire.GriefPrevention.events.PreventBlockBreakEvent;
import me.ryanhamshire.GriefPrevention.events.SaveTrappedPlayerEvent;
import me.ryanhamshire.GriefPrevention.events.TrustChangedEvent;
import me.ryanhamshire.GriefPrevention.alttd.listeners.AltitudeListener;
import me.ryanhamshire.GriefPrevention.alttd.hook.Pl3xMapHook;
import me.ryanhamshire.GriefPrevention.metrics.MetricsHandler;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
@ -243,6 +244,7 @@ public class GriefPrevention extends JavaPlugin
private String databaseUserName;
private String databasePassword;
private Pl3xMapHook pl3xmapHook;
//how far away to search from a tree trunk for its branch blocks
public static final int TREE_RADIUS = 5;
@ -398,6 +400,9 @@ public class GriefPrevention extends JavaPlugin
}
new AltitudeListener(this.dataStore, this);
if (getServer().getPluginManager().isPluginEnabled("Pl3xMap")) {
pl3xmapHook = new Pl3xMapHook(this);
}
AddLogEntry("Boot finished.");
try
@ -3328,6 +3333,10 @@ public class GriefPrevention extends JavaPlugin
//dump any remaining unwritten log entries
this.customLogger.WriteEntries();
if (pl3xmapHook != null) {
pl3xmapHook.disable();
}
AddLogEntry("GriefPrevention disabled.");
}

View File

@ -5,6 +5,7 @@ import me.ryanhamshire.GriefPrevention.GriefPrevention;
import me.ryanhamshire.GriefPrevention.alttd.util.Logger;
import org.spongepowered.configurate.ConfigurationNode;
import java.awt.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@ -44,6 +45,24 @@ public class AlttdConfig extends AbstractConfiguration
return map;
}
Color getColor(String path, Color def) {
config.set(path, colorToHex(def));
return hexToColor(config.getString(path, colorToHex(def)));
}
String colorToHex(final Color color) {
return Integer.toHexString(color.getRGB() & 0x00FFFFFF);
}
Color hexToColor(final String hex) {
if (hex == null) {
return Color.RED;
}
String stripped = hex.replace("#", "");
int rgb = (int) Long.parseLong(stripped, 16);
return new Color(rgb);
}
public static boolean DEBUG_MODE = false;
public static boolean alternativeClaimExpiring = false;
public static int alternativeClaimExpireDays = 1;
@ -71,4 +90,79 @@ public class AlttdConfig extends AbstractConfiguration
config.saveConfig();
}
public static String CONTROL_LABEL = "GriefPrevention";
public static boolean CONTROL_SHOW = true;
public static boolean CONTROL_HIDE = false;
public static String GRID_CONTROL_LABEL = "Gridlines";
public static boolean GRID_CONTROL_SHOW = true;
public static boolean GRID_CONTROL_HIDE = true;
public static int UPDATE_INTERVAL = 300;
public static Color STROKE_COLOR = Color.GREEN;
public static int STROKE_WEIGHT = 1;
public static double STROKE_OPACITY = 1.0D;
public static Color FILL_COLOR = Color.GREEN;
public static double FILL_OPACITY = 0.2D;
public static Color ADMIN_STROKE_COLOR = Color.BLUE;
public static int ADMIN_STROKE_WEIGHT = 1;
public static double ADMIN_STROKE_OPACITY = 1.0D;
public static Color ADMIN_FILL_COLOR = Color.BLUE;
public static double ADMIN_FILL_OPACITY = 0.2D;
public static Color EXPIRING_STROKE_COLOR = Color.PINK;
public static int EXPIRING_STROKE_WEIGHT = 1;
public static double EXPIRING_STROKE_OPACITY = 1.0D;
public static Color EXPIRING_FILL_COLOR = Color.PINK;
public static double EXPIRING_FILL_OPACITY = 0.2D;
public static String STRINGS_PUBLIC = "Public";
public static String CLAIM_TOOLTIP = "Claim Owner: <span style=\"font-weight:bold;\">{owner}</span><br/>" +
"Permission Trust: <span style=\"font-weight:bold;\">{managers}</span><br/>" +
"Trust: <span style=\"font-weight:bold;\">{builders}</span><br/>" +
"Container Trust: <span style=\"font-weight:bold;\">{containers}</span><br/>" +
"Access Trust: <span style=\"font-weight:bold;\">{accessors}</span>";
public static String ADMIN_CLAIM_TOOLTIP = "<span style=\"font-weight:bold;\">Administrator Claim</span><br/>" +
"Permission Trust: <span style=\"font-weight:bold;\">{managers}</span><br/>" +
"Trust: <span style=\"font-weight:bold;\">{builders}</span><br/>" +
"Container Trust: <span style=\"font-weight:bold;\">{containers}</span><br/>" +
"Access Trust: <span style=\"font-weight:bold;\">{accessors}</span>";
public static String EXPIRING_CLAIM_TOOLTIP = "<span style=\"font-weight:bold;\">Temporary Claim</span><br/>" +
"Permission Trust: <span style=\"font-weight:bold;\">{managers}</span><br/>" +
"Trust: <span style=\"font-weight:bold;\">{builders}</span><br/>" +
"Container Trust: <span style=\"font-weight:bold;\">{containers}</span><br/>" +
"Access Trust: <span style=\"font-weight:bold;\">{accessors}</span><br/>" +
"Expires: <span style=\"font-weight:bold;\">{expiretime}</span>" ;
private static void mapSettings() {
CONTROL_LABEL = config.getString("settings.control.label", CONTROL_LABEL);
CONTROL_SHOW = config.getBoolean("settings.control.show", CONTROL_SHOW);
CONTROL_HIDE = config.getBoolean("settings.control.hide-by-default", CONTROL_HIDE);
GRID_CONTROL_LABEL = config.getString("settings.grid.label", GRID_CONTROL_LABEL);
GRID_CONTROL_SHOW = config.getBoolean("settings.grid.show", GRID_CONTROL_SHOW);
GRID_CONTROL_HIDE = config.getBoolean("settings.grid.hide-by-default", GRID_CONTROL_HIDE);
UPDATE_INTERVAL = config.getInt("settings.update-interval", UPDATE_INTERVAL);
STROKE_COLOR = config.getColor("settings.style.regular-claim.stroke.color", STROKE_COLOR);
STROKE_WEIGHT = config.getInt("settings.style.regular-claim.stroke.weight", STROKE_WEIGHT);
STROKE_OPACITY = config.getDouble("settings.regular-claim.style.stroke.opacity", STROKE_OPACITY);
FILL_COLOR = config.getColor("settings.style.regular-claim.fill.color", FILL_COLOR);
FILL_OPACITY = config.getDouble("settings.style.regular-claim.fill.opacity", FILL_OPACITY);
ADMIN_STROKE_COLOR = config.getColor("settings.style.admin-claim.stroke.color", ADMIN_STROKE_COLOR);
ADMIN_STROKE_WEIGHT = config.getInt("settings.style.admin-claim.stroke.weight", ADMIN_STROKE_WEIGHT);
ADMIN_STROKE_OPACITY = config.getDouble("settings.admin-claim.style.stroke.opacity", ADMIN_STROKE_OPACITY);
ADMIN_FILL_COLOR = config.getColor("settings.style.admin-claim.fill.color", ADMIN_FILL_COLOR);
ADMIN_FILL_OPACITY = config.getDouble("settings.style.admin-claim.fill.opacity", ADMIN_FILL_OPACITY);
EXPIRING_STROKE_COLOR = config.getColor("settings.style.expiring-claim.stroke.color", EXPIRING_STROKE_COLOR);
EXPIRING_STROKE_WEIGHT = config.getInt("settings.style.expiring-claim.stroke.weight", EXPIRING_STROKE_WEIGHT);
EXPIRING_STROKE_OPACITY = config.getDouble("settings.expiring-claim.style.stroke.opacity", EXPIRING_STROKE_OPACITY);
EXPIRING_FILL_COLOR = config.getColor("settings.style.expiring-claim.fill.color", EXPIRING_FILL_COLOR);
EXPIRING_FILL_OPACITY = config.getDouble("settings.style.expiring-claim.fill.opacity", EXPIRING_FILL_OPACITY);
STRINGS_PUBLIC = config.getString("settings.strings.public", STRINGS_PUBLIC);
CLAIM_TOOLTIP = config.getString("settings.region.tooltip.regular-claim", CLAIM_TOOLTIP);
ADMIN_CLAIM_TOOLTIP = config.getString("settings.region.tooltip.admin-claim", ADMIN_CLAIM_TOOLTIP);
EXPIRING_CLAIM_TOOLTIP = config.getString("settings.region.tooltip.expiring-claim", EXPIRING_CLAIM_TOOLTIP);
}
}

View File

@ -0,0 +1,20 @@
package me.ryanhamshire.GriefPrevention.alttd.hook;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.util.Collection;
import java.util.UUID;
public class GPHook {
public static boolean isWorldEnabled(UUID uuid) {
World world = Bukkit.getWorld(uuid);
return GriefPrevention.instance.claimsEnabledForWorld(world);
}
public static Collection<Claim> getClaims() {
return GriefPrevention.instance.dataStore.getClaims();
}
}

View File

@ -0,0 +1,39 @@
package me.ryanhamshire.GriefPrevention.alttd.hook;
import me.ryanhamshire.GriefPrevention.alttd.config.AlttdConfig;
import me.ryanhamshire.GriefPrevention.alttd.tasks.Pl3xMapTask;
import net.pl3x.map.api.Key;
import net.pl3x.map.api.Pl3xMapProvider;
import net.pl3x.map.api.SimpleLayerProvider;
import org.bukkit.plugin.Plugin;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class Pl3xMapHook {
private final Map<UUID, Pl3xMapTask> provider = new HashMap<>();
public Pl3xMapHook(Plugin plugin) {
plugin.getLogger().info("Started Pl3xMapHook...");
Pl3xMapProvider.get().mapWorlds().forEach(world -> {
if (GPHook.isWorldEnabled(world.uuid())) {
SimpleLayerProvider provider = SimpleLayerProvider
.builder(AlttdConfig.CONTROL_LABEL)
.showControls(AlttdConfig.CONTROL_SHOW)
.defaultHidden(AlttdConfig.CONTROL_HIDE)
.build();
world.layerRegistry().register(Key.of("griefprevention_" + world.uuid()), provider);
Pl3xMapTask task = new Pl3xMapTask(world, provider);
task.runTaskTimerAsynchronously(plugin, 0, 20L * AlttdConfig.UPDATE_INTERVAL);
this.provider.put(world.uuid(), task);
}
});
}
public void disable() {
provider.values().forEach(Pl3xMapTask::disable);
provider.clear();
}
}

View File

@ -0,0 +1,126 @@
package me.ryanhamshire.GriefPrevention.alttd.tasks;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.alttd.config.AlttdConfig;
import me.ryanhamshire.GriefPrevention.alttd.hook.GPHook;
import net.pl3x.map.api.Key;
import net.pl3x.map.api.MapWorld;
import net.pl3x.map.api.Point;
import net.pl3x.map.api.SimpleLayerProvider;
import net.pl3x.map.api.marker.Marker;
import net.pl3x.map.api.marker.MarkerOptions;
import net.pl3x.map.api.marker.Rectangle;
import org.bukkit.Location;
import org.bukkit.scheduler.BukkitRunnable;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class Pl3xMapTask extends BukkitRunnable {
private final MapWorld world;
private final SimpleLayerProvider provider;
private boolean stop;
public Pl3xMapTask(MapWorld world, SimpleLayerProvider provider) {
this.world = world;
this.provider = provider;
}
@Override
public void run() {
if (stop) {
cancel();
}
updateClaims();
}
void updateClaims() {
provider.clearMarkers();
Collection<Claim> topLevelClaims = GPHook.getClaims();
if (topLevelClaims != null) {
topLevelClaims.stream()
.filter(claim -> claim.getGreaterBoundaryCorner().getWorld().getUID().equals(this.world.uuid()))
.filter(claim -> claim.parent == null)
.forEach(this::handleClaim);
}
}
private void handleClaim(Claim claim) {
Location min = claim.getLesserBoundaryCorner();
Location max = claim.getGreaterBoundaryCorner();
if (min == null) {
return;
}
Rectangle rect = Marker.rectangle(Point.of(min.getBlockX(), min.getBlockZ()), Point.of(max.getBlockX() + 1, max.getBlockZ() + 1));
ArrayList<String> builders = new ArrayList<>();
ArrayList<String> containers = new ArrayList<>();
ArrayList<String> accessors = new ArrayList<>();
ArrayList<String> managers = new ArrayList<>();
claim.getPermissions(builders, containers, accessors, managers);
String worldName = min.getWorld().getName();
String toolTip = AlttdConfig.CLAIM_TOOLTIP;
MarkerOptions.Builder options = MarkerOptions.builder()
.strokeColor(AlttdConfig.STROKE_COLOR)
.strokeWeight(AlttdConfig.STROKE_WEIGHT)
.strokeOpacity(AlttdConfig.STROKE_OPACITY)
.fillColor(AlttdConfig.FILL_COLOR)
.fillOpacity(AlttdConfig.FILL_OPACITY)
.clickTooltip((claim.isAdminClaim() ? (AlttdConfig.expiringClaims.containsKey(claim.getID()) ? AlttdConfig.EXPIRING_CLAIM_TOOLTIP : AlttdConfig.ADMIN_CLAIM_TOOLTIP) : AlttdConfig.CLAIM_TOOLTIP)
.replace("{world}", worldName)
.replace("{id}", Long.toString(claim.getID()))
.replace("{owner}", claim.getOwnerName())
.replace("{managers}", getNames(managers))
.replace("{builders}", getNames(builders))
.replace("{containers}", getNames(containers))
.replace("{accessors}", getNames(accessors))
.replace("{area}", Integer.toString(claim.getArea()))
.replace("{width}", Integer.toString(claim.getWidth()))
.replace("{height}", Integer.toString(claim.getHeight()))
.replace("{expiretime}", parseExpireTime(claim.getID()))
);
if (claim.isAdminClaim()) {
if (AlttdConfig.expiringClaims.containsKey(claim.getID())) {
options.strokeColor(AlttdConfig.EXPIRING_STROKE_COLOR)
.strokeWeight(AlttdConfig.EXPIRING_STROKE_WEIGHT)
.strokeOpacity(AlttdConfig.EXPIRING_STROKE_OPACITY)
.fillColor(AlttdConfig.EXPIRING_FILL_COLOR)
.fillOpacity(AlttdConfig.EXPIRING_FILL_OPACITY);
} else {
options.strokeColor(AlttdConfig.ADMIN_STROKE_COLOR)
.strokeWeight(AlttdConfig.ADMIN_STROKE_WEIGHT)
.strokeOpacity(AlttdConfig.ADMIN_STROKE_OPACITY)
.fillColor(AlttdConfig.ADMIN_FILL_COLOR)
.fillOpacity(AlttdConfig.ADMIN_FILL_OPACITY);
}
}
rect.markerOptions(options);
String markerid = "griefprevention_" + worldName + "_region_" + Long.toHexString(claim.getID());
this.provider.addMarker(Key.of(markerid), rect);
}
private static String getNames(List<String> list) {
return String.join(", ", list);
}
public void disable() {
cancel();
this.stop = true;
this.provider.clearMarkers();
}
private String parseExpireTime(Long claimId) {
if(AlttdConfig.expiringClaims.containsKey(claimId)) {
return DateFormat.getInstance().format(AlttdConfig.expiringClaims.get(claimId));
}
return "";
}
}

View File

@ -1,6 +1,6 @@
name: GriefPrevention
main: me.ryanhamshire.GriefPrevention.GriefPrevention
softdepend: [Vault, Multiverse-Core, My_Worlds, MystCraft, Transporter, TheUnderground, WorldGuard, WorldEdit, RoyalCommands, MultiWorld, Denizen]
softdepend: [Vault, Multiverse-Core, My_Worlds, MystCraft, Transporter, TheUnderground, WorldGuard, WorldEdit, RoyalCommands, MultiWorld, Denizen, Pl3xMap]
dev-url: https://dev.bukkit.org/projects/grief-prevention
loadbefore: [TheUnderground]
version: '${git.commit.id.describe}'