Skip to content

Commit

Permalink
Merge pull request #440 from VolmitSoftware/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
NextdoorPsycho authored Jun 5, 2023
2 parents 7eaebe8 + 9eb2d0c commit 7be87d5
Show file tree
Hide file tree
Showing 7 changed files with 568 additions and 184 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins {
id "de.undercouch.download" version "5.0.1"
}

version '1.10.1-1.19.4'
version '1.10.2-1.19.4'
def nmsVersion = "1.19.4" //[NMS]
def apiVersion = '1.19'
def specialSourceVersion = '1.11.0' //[NMS]
Expand Down Expand Up @@ -150,8 +150,8 @@ dependencies {
compileOnly 'net.kyori:adventure-text-minimessage:4.13.1'
compileOnly 'net.kyori:adventure-platform-bukkit:4.3.0'
compileOnly 'net.kyori:adventure-api:4.13.1'
compileOnly 'io.github.mqzn:mCommands-spigot:1.0.9'
compileOnly 'io.github.mqzn:mCommands-common:1.0.9'
compileOnly 'io.github.mqzn:mCommands-spigot:1.1.0'
compileOnly 'io.github.mqzn:mCommands-common:1.1.0'
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,85 +1,93 @@
package com.volmit.adapt.content.protector;

import com.bekvon.bukkit.residence.Residence;
import com.bekvon.bukkit.residence.containers.Flags;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.FlagPermissions;
import com.volmit.adapt.Adapt;
import com.volmit.adapt.AdaptConfig;
import com.volmit.adapt.api.adaptation.Adaptation;
import com.volmit.adapt.api.protection.Protector;
import org.bukkit.Location;
import org.bukkit.entity.Player;

public class ResidenceProtector implements Protector {

public ResidenceProtector() {
FlagPermissions.addFlag("use-adaptations");
}

@Override
public boolean checkRegion(Player player, Location location, Adaptation<?> adaptation) {
return checkPerm(player, location, "use-adaptations");
}

@Override
public boolean canBlockBreak(Player player, Location blockLocation, Adaptation<?> adaptation) {
return checkRegion(player, blockLocation, adaptation) && checkPerm(player, blockLocation, Flags.destroy);
}

@Override
public boolean canBlockPlace(Player player, Location blockLocation, Adaptation<?> adaptation) {
return checkRegion(player, blockLocation, adaptation) && checkPerm(player, blockLocation, Flags.place);
}

@Override
public boolean canPVP(Player player, Location entityLocation, Adaptation<?> adaptation) {
return checkRegion(player, entityLocation, adaptation) && checkPerm(player, entityLocation, Flags.pvp);
}

@Override
public boolean canPVE(Player player, Location entityLocation, Adaptation<?> adaptation) {
return checkRegion(player, entityLocation, adaptation) && checkPerm(player, entityLocation, Flags.damage);
}

@Override
public boolean canInteract(Player player, Location targetLocation, Adaptation<?> adaptation) {
return checkRegion(player, targetLocation, adaptation) && checkPerm(player, targetLocation, Flags.use);
}

@Override
public boolean canAccessChest(Player player, Location chestLocation, Adaptation<?> adaptation) {
return checkRegion(player, chestLocation, adaptation) && checkPerm(player, chestLocation, Flags.container);
}

private boolean checkPerm(Player player, Location location, Flags flag) {
if (!Residence.getInstance().isDisabledWorld(location.getWorld())) {
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location);
if (res != null) {
return res.getPermissions().playerHas(player.getName(), flag, true);
}
}
return true;
}

private boolean checkPerm(Player player, Location location, String flag) {
if (!Residence.getInstance().isDisabledWorld(location.getWorld())) {
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location);
if (res != null) {
return res.getPermissions().playerHas(player.getName(), flag, true);
}
}
return true;
}

@Override
public String getName() {
return "Residence";
}

@Override
public boolean isEnabledByDefault() {
return AdaptConfig.get().getProtectorSupport().isResidence();
}

}
package com.volmit.adapt.content.protector;

import com.bekvon.bukkit.residence.Residence;
import com.bekvon.bukkit.residence.containers.Flags;
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
import com.bekvon.bukkit.residence.protection.FlagPermissions;
import com.volmit.adapt.AdaptConfig;
import com.volmit.adapt.api.adaptation.Adaptation;
import com.volmit.adapt.api.protection.Protector;
import com.volmit.adapt.util.J;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.util.concurrent.atomic.AtomicBoolean;

public class ResidenceProtector implements Protector {

public ResidenceProtector() {
FlagPermissions.addFlag("use-adaptations");
}

@Override
public boolean checkRegion(Player player, Location location, Adaptation<?> adaptation) {
return checkPerm(player, location, "use-adaptations");
}

@Override
public boolean canBlockBreak(Player player, Location blockLocation, Adaptation<?> adaptation) {
return checkRegion(player, blockLocation, adaptation) && checkPerm(player, blockLocation, Flags.destroy);
}

@Override
public boolean canBlockPlace(Player player, Location blockLocation, Adaptation<?> adaptation) {
return checkRegion(player, blockLocation, adaptation) && checkPerm(player, blockLocation, Flags.place);
}

@Override
public boolean canPVP(Player player, Location entityLocation, Adaptation<?> adaptation) {
return checkRegion(player, entityLocation, adaptation) && checkPerm(player, entityLocation, Flags.pvp);
}

@Override
public boolean canPVE(Player player, Location entityLocation, Adaptation<?> adaptation) {
return checkRegion(player, entityLocation, adaptation) && checkPerm(player, entityLocation, Flags.damage);
}

@Override
public boolean canInteract(Player player, Location targetLocation, Adaptation<?> adaptation) {
return checkRegion(player, targetLocation, adaptation) && checkPerm(player, targetLocation, Flags.use);
}

@Override
public boolean canAccessChest(Player player, Location chestLocation, Adaptation<?> adaptation) {
return checkRegion(player, chestLocation, adaptation) && checkPerm(player, chestLocation, Flags.container);
}

private boolean checkPerm(Player player, Location location, Flags flag) {
AtomicBoolean perm = new AtomicBoolean(false);
J.s(() -> {
if (!Residence.getInstance().isDisabledWorld(location.getWorld())) {
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location);
if (res != null) {
perm.set(res.getPermissions().playerHas(player.getName(), flag, true));
}
}
});
return perm.get();
}

private boolean checkPerm(Player player, Location location, String flag) {
AtomicBoolean perm = new AtomicBoolean(false);
J.s(() -> {
if (!Residence.getInstance().isDisabledWorld(location.getWorld())) {
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location);
if (res != null) {
perm.set(res.getPermissions().playerHas(player.getName(), flag, true));
}
}
});
return true;
}

@Override
public String getName() {
return "Residence";
}

@Override
public boolean isEnabledByDefault() {
return AdaptConfig.get().getProtectorSupport().isResidence();
}

}
Loading

0 comments on commit 7be87d5

Please sign in to comment.