Skip to content

Commit

Permalink
Ported over to GriefDefender
Browse files Browse the repository at this point in the history
  • Loading branch information
sarhatabaot committed Jun 8, 2021
1 parent de1c1ff commit 2612e13
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 71 deletions.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.pl3x.map.griefprevention</groupId>
<artifactId>pl3xmap-griefprevention</artifactId>
<name>Pl3xmap-GriefPrevention</name>
<groupId>net.pl3x.map.griefdefender</groupId>
<artifactId>pl3xmap-griefdefender</artifactId>
<name>Pl3xmap-Defender</name>
<version>1.0-SNAPSHOT</version>
<description>GriefPrevention addon for Pl3xMap</description>
<description>GriefDefender addon for Pl3xMap</description>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -26,9 +26,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.TechFortress</groupId>
<artifactId>GriefPrevention</artifactId>
<version>16.17.1</version>
<groupId>com.github.bloodmc</groupId>
<artifactId>GriefDefenderAPI</artifactId>
<version>-dd5aa2224c-1</version>
</dependency>
</dependencies>
<repositories>
Expand All @@ -47,7 +47,7 @@
</repositories>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<defaultGoal>clean install</defaultGoal>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package net.pl3x.map.griefprevention;
package net.pl3x.map.griefdefender;

import net.pl3x.map.griefprevention.configuration.Config;
import net.pl3x.map.griefprevention.hook.Pl3xMapHook;
import net.pl3x.map.griefdefender.configuration.Config;
import net.pl3x.map.griefdefender.hook.Pl3xMapHook;
import org.bukkit.plugin.java.JavaPlugin;

public final class Pl3xMapGriefprevention extends JavaPlugin {
public final class Pl3xMapGriefdefender extends JavaPlugin {
private Pl3xMapHook pl3xmapHook;

@Override
public void onEnable() {
Config.reload(this);

if (!getServer().getPluginManager().isPluginEnabled("GriefPrevention")) {
getLogger().severe("GriefPrevention not found!");
if (!getServer().getPluginManager().isPluginEnabled("GriefDefender")) {
getLogger().severe("GriefDefender not found!");
getServer().getPluginManager().disablePlugin(this);
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.pl3x.map.griefprevention.configuration;
package net.pl3x.map.griefdefender.configuration;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
Expand All @@ -9,7 +9,7 @@
import java.io.IOException;

public class Config {
public static String CONTROL_LABEL = "GriefPrevention";
public static String CONTROL_LABEL = "GriefDefender";
public static boolean CONTROL_SHOW = true;
public static boolean CONTROL_HIDE = false;
public static int UPDATE_INTERVAL = 300;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/net/pl3x/map/griefdefender/hook/GPHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.pl3x.map.griefdefender.hook;

import com.griefdefender.api.GriefDefender;
import com.griefdefender.api.claim.Claim;

import java.util.Collection;
import java.util.UUID;

public class GPHook {
public static boolean isWorldEnabled(UUID uuid) {
return GriefDefender.getCore().isEnabled(uuid);
}

public static Collection<Claim> getClaims() {
return GriefDefender.getCore().getAllClaims();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package net.pl3x.map.griefprevention.hook;
package net.pl3x.map.griefdefender.hook;

import net.pl3x.map.api.Key;
import net.pl3x.map.api.Pl3xMapProvider;
import net.pl3x.map.api.SimpleLayerProvider;
import net.pl3x.map.griefprevention.configuration.Config;
import net.pl3x.map.griefprevention.task.Pl3xMapTask;
import net.pl3x.map.griefdefender.configuration.Config;
import net.pl3x.map.griefdefender.task.Pl3xMapTask;
import org.bukkit.plugin.Plugin;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package net.pl3x.map.griefprevention.task;
package net.pl3x.map.griefdefender.task;

import me.ryanhamshire.GriefPrevention.Claim;
import com.flowpowered.math.vector.Vector3i;
import com.griefdefender.api.claim.Claim;
import com.griefdefender.api.claim.TrustTypes;
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 net.pl3x.map.griefprevention.configuration.Config;
import net.pl3x.map.griefprevention.hook.GPHook;
import net.pl3x.map.griefdefender.configuration.Config;
import net.pl3x.map.griefdefender.hook.GPHook;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable;

import java.awt.Color;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

public class Pl3xMapTask extends BukkitRunnable {
private final MapWorld world;
Expand All @@ -46,28 +46,26 @@ void updateClaims() {
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)
.filter(claim -> claim.getWorldUniqueId().equals(this.world.uuid()))
.filter(claim -> !claim.getParent().isPresent())
.forEach(this::handleClaim);
}
}

private void handleClaim(Claim claim) {
Location min = claim.getLesserBoundaryCorner();
Location max = claim.getGreaterBoundaryCorner();
Vector3i min = claim.getLesserBoundaryCorner();
Vector3i max = claim.getGreaterBoundaryCorner();
if (min == null) {
return;
}
Rectangle rect = Marker.rectangle(Point.of(min.getX(), min.getZ()), Point.of(max.getX() + 1, max.getZ() + 1));

Rectangle rect = Marker.rectangle(Point.of(min.getBlockX(), min.getBlockZ()), Point.of(max.getBlockX() + 1, max.getBlockZ() + 1));
ArrayList<UUID> builders = new ArrayList<>(claim.getUserTrusts(TrustTypes.BUILDER));
ArrayList<UUID> containers = new ArrayList<>(claim.getUserTrusts(TrustTypes.CONTAINER));
ArrayList<UUID> accessors = new ArrayList<>(claim.getUserTrusts(TrustTypes.ACCESSOR));
ArrayList<UUID> managers = new ArrayList<>(claim.getUserTrusts(TrustTypes.MANAGER));

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 worldName = Bukkit.getWorld(claim.getWorldUniqueId()).getName();

MarkerOptions.Builder options = MarkerOptions.builder()
.strokeColor(Config.STROKE_COLOR)
Expand All @@ -77,7 +75,7 @@ private void handleClaim(Claim claim) {
.fillOpacity(Config.FILL_OPACITY)
.clickTooltip((claim.isAdminClaim() ? Config.ADMIN_CLAIM_TOOLTIP : Config.CLAIM_TOOLTIP)
.replace("{world}", worldName)
.replace("{id}", Long.toString(claim.getID()))
.replace("{id}", claim.getUniqueId().toString())
.replace("{owner}", claim.getOwnerName())
.replace("{managers}", getNames(managers))
.replace("{builders}", getNames(builders))
Expand All @@ -94,20 +92,15 @@ private void handleClaim(Claim claim) {

rect.markerOptions(options);

String markerid = "griefprevention_" + worldName + "_region_" + Long.toHexString(claim.getID());
String markerid = "griefprevention_" + worldName + "_region_" + claim.getUniqueId().toString();
this.provider.addMarker(Key.of(markerid), rect);
}

private static String getNames(List<String> list) {
private static String getNames(List<UUID> list) {
List<String> names = new ArrayList<>();
for (String str : list) {
try {
UUID uuid = UUID.fromString(str);
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
names.add(offlinePlayer.getName());
} catch (Exception e) {
names.add(str);
}
for (final UUID uuid : list) {
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
names.add(offlinePlayer.getName());
}
return String.join(", ", names);
}
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/net/pl3x/map/griefprevention/hook/GPHook.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: "${project.name}"
main: "${project.groupId}.Pl3xMapGriefprevention"
main: "${project.groupId}.Pl3xMapGriefdefender"
version: "${project.version}"
description: "${project.description}"
api-version: "1.16"
authors: [ BillyGalbreath ]
softdepend:
- GriefPrevention
- GriefDefender
- Pl3xMap

0 comments on commit 2612e13

Please sign in to comment.