127 lines
5.1 KiB
Java
127 lines
5.1 KiB
Java
|
|
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 "";
|
||
|
|
}
|
||
|
|
}
|