mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-10-22 12:20:26 +02:00
Added BentoBox protection support, and dodged an NPE in GriefPrevention.
This commit is contained in:
parent
44673e3ed0
commit
86bffc859c
@ -368,6 +368,12 @@
|
||||
<version>0.96.5.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>world.bentobox</groupId>
|
||||
<artifactId>bentobox</artifactId>
|
||||
<version>1.15.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- End Plugin Hooks -->
|
||||
<dependency>
|
||||
|
@ -45,6 +45,7 @@ public final class PluginHook<T extends Class> {
|
||||
public static final PluginHook PROTECTION_REDPROTECT = new PluginHook(Protection.class, "RedProtect", RedProtectProtection.class);
|
||||
public static final PluginHook PROTECTION_ULTIMATECLAIMS = new PluginHook(Protection.class, "UltimateClaims", UltimateClaimsProtection.class);
|
||||
public static final PluginHook PROTECTION_TOWNY = new PluginHook(Protection.class, "Towny", TownyProtection.class);
|
||||
public static final PluginHook PROTECTION_BENTOBOX = new PluginHook(Protection.class, "BentoBox", BentoBoxProtection.class);
|
||||
|
||||
/******* Start Manager stuff *******/
|
||||
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.songoda.core.hooks.protection;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.managers.IslandsManager;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class BentoBoxProtection extends Protection {
|
||||
|
||||
private final IslandsManager islandsManager;
|
||||
|
||||
public BentoBoxProtection(Plugin plugin) {
|
||||
super(plugin);
|
||||
this.islandsManager = BentoBox.getInstance().getIslands();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Player player, Location location) {
|
||||
return hasPerms(player, location, Flags.PLACE_BLOCKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Player player, Location location) {
|
||||
return hasPerms(player, location, Flags.BREAK_BLOCKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Location location) {
|
||||
return hasPerms(player, location, Flags.CONTAINER);
|
||||
}
|
||||
|
||||
private boolean hasPerms(Player player, Location location, Flag flag) {
|
||||
if (!BentoBox.getInstance().getIWM().inWorld(location)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Optional<Island> optional = islandsManager.getIslandAt(location);
|
||||
if (!optional.isPresent()) {
|
||||
return flag.isSetForWorld(location.getWorld());
|
||||
}
|
||||
|
||||
Island island = optional.get();
|
||||
User user = User.getInstance(player);
|
||||
|
||||
return island.isAllowed(user, flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BentoBox";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -18,17 +18,29 @@ public class GriefPreventionProtection extends Protection {
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Player player, Location location) {
|
||||
return getClaim(location).allowBuild(player, location.getBlock().getType()) == null;
|
||||
Claim claim = getClaim(location);
|
||||
if (claim == null) {
|
||||
return true;
|
||||
}
|
||||
return claim.allowBuild(player, location.getBlock().getType()) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Player player, Location location) {
|
||||
return getClaim(location).allowBreak(player, location.getBlock().getType()) == null;
|
||||
Claim claim = getClaim(location);
|
||||
if (claim == null) {
|
||||
return true;
|
||||
}
|
||||
return claim.allowBreak(player, location.getBlock().getType()) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Location location) {
|
||||
return getClaim(location).allowContainers(player) == null;
|
||||
Claim claim = getClaim(location);
|
||||
if (claim == null) {
|
||||
return true;
|
||||
}
|
||||
return claim.allowContainers(player) == null;
|
||||
}
|
||||
|
||||
private Claim getClaim(Location location) {
|
||||
|
Loading…
Reference in New Issue
Block a user