Skip to content

Commit

Permalink
[Compatibility] PlotSquaredV5
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiao-MoMi committed Apr 21, 2024
1 parent 36cf483 commit 731669f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
1 change: 1 addition & 0 deletions conflict-packages/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ dependencies {
implementation(project(":common"))
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") // Paper
compileOnly("com.github.SaberLLC:Saber-Factions:4.1.2-STABLE") // SaberFactions
compileOnly(files("libs/PlotSquared-pruned.jar")) // PlotSquaredV5
}
Binary file added conflict-packages/libs/PlotSquared-pruned.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.momirealms.antigrieflib.comp;

import com.plotsquared.bukkit.util.BukkitUtil;
import net.momirealms.antigrieflib.AbstractComp;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
Expand All @@ -8,9 +9,9 @@

import java.util.Optional;

public class PlotSquaredComp extends AbstractComp {
public class PlotSquaredV5Comp extends AbstractComp {

public PlotSquaredComp(JavaPlugin plugin) {
public PlotSquaredV5Comp(JavaPlugin plugin) {
super(plugin, "PlotSquared");
}

Expand Down Expand Up @@ -44,9 +45,9 @@ public boolean canDamage(Player player, Entity entity) {
}

private boolean isPlotMember(Player player, Location location) {
var psLocation = com.plotsquared.core.location.Location.at(location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ());
var psLocation = BukkitUtil.getLocation(location);
if (psLocation.isPlotRoad()) return false;
if (!psLocation.isPlotArea()) return true;
return Optional.ofNullable(psLocation.getPlotArea().getPlot(psLocation)).map(plot -> plot.isAdded(player.getUniqueId())).orElse(false);
return Optional.ofNullable(psLocation.getPlotArea().getPlot(psLocation)).map(plot -> plot.isAdded(player.getUniqueId()) || plot.isOwner(player.getUniqueId())).orElse(false);
}
}
2 changes: 1 addition & 1 deletion project/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
compileOnly("com.massivecraft:Factions:1.6.9.5-U0.6.33") // FactionsUUID
compileOnly("dev.espi:protectionstones:2.10.2") // ProtectionStones
compileOnly("biz.princeps:landlord-core:4.364") // Landlord
// compileOnly("ovh.uskyblock:uSkyBlock-Core:3.0.0") // uSkyBlock (Removed because it's repo is down)
// compileOnly("ovh.uskyblock:uSkyBlock-Core:3.0.0") // uSkyBlock (Removed because its repo is down)
compileOnly("com.github.UlrichBR:UClansV7-API:7.4.0-r1") // UltimateClans

compileOnly(files("libs/Residence-pruned.jar")) // Residence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ private void detectSupportedPlugins() {
registerNewCompatibility(new HuskTownsComp(plugin));
}
if (manager.getPlugin("PlotSquared") != null) {
registerNewCompatibility(new PlotSquaredComp(plugin));
switch (manager.getPlugin("PlotSquared").getDescription().getVersion().charAt(0)) {
case '5' -> registerNewCompatibility(new PlotSquaredV5Comp(plugin));
case '6', '7' -> registerNewCompatibility(new PlotSquaredV6V7Comp(plugin));
}
}
if (manager.getPlugin("Residence") != null) {
registerNewCompatibility(new ResidenceComp(plugin));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.momirealms.antigrieflib.comp;

import com.plotsquared.bukkit.util.BukkitUtil;
import net.momirealms.antigrieflib.AbstractComp;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Optional;

public class PlotSquaredV6V7Comp extends AbstractComp {

public PlotSquaredV6V7Comp(JavaPlugin plugin) {
super(plugin, "PlotSquared");
}

@Override
public void init() {
}

@Override
public boolean canPlace(Player player, Location location) {
return isPlotMember(player, location);
}

@Override
public boolean canBreak(Player player, Location location) {
return isPlotMember(player, location);
}

@Override
public boolean canInteract(Player player, Location location) {
return isPlotMember(player, location);
}

@Override
public boolean canInteractEntity(Player player, Entity entity) {
return isPlotMember(player, entity.getLocation());
}

@Override
public boolean canDamage(Player player, Entity entity) {
return isPlotMember(player, entity.getLocation());
}

private boolean isPlotMember(Player player, Location location) {
var psLocation = BukkitUtil.adapt(location);
if (psLocation.isPlotRoad()) return false;
if (!psLocation.isPlotArea()) return true;
return Optional.ofNullable(psLocation.getPlotArea().getPlot(psLocation)).map(plot -> plot.isAdded(player.getUniqueId()) || plot.isOwner(player.getUniqueId())).orElse(false);
}
}

0 comments on commit 731669f

Please sign in to comment.