mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-27 12:35:12 +01:00
Added protection hooks.
This commit is contained in:
parent
30f240cbfd
commit
fe7dcd80fe
23
Core/pom.xml
23
Core/pom.xml
@ -338,6 +338,29 @@
|
||||
<version>2.17.5</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.ryanhamshire</groupId>
|
||||
<artifactId>GriefPrevention</artifactId>
|
||||
<version>16.16.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.angeschossen</groupId>
|
||||
<artifactId>LandsAPI</artifactId>
|
||||
<version>4.12.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>br.net.fabiozumbi12</groupId>
|
||||
<artifactId>RedProtect</artifactId>
|
||||
<version>7.7.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateClaims</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- End Plugin Hooks -->
|
||||
<dependency>
|
||||
|
@ -10,10 +10,15 @@ import com.songoda.core.hooks.holograms.HologramsHolograms;
|
||||
import com.songoda.core.hooks.holograms.HolographicDisplaysHolograms;
|
||||
import com.songoda.core.hooks.log.CoreProtectLog;
|
||||
import com.songoda.core.hooks.log.Log;
|
||||
import com.songoda.core.hooks.protection.GriefPreventionProtection;
|
||||
import com.songoda.core.hooks.protection.LandsProtection;
|
||||
import com.songoda.core.hooks.protection.Protection;
|
||||
import com.songoda.core.hooks.protection.RedProtectProtection;
|
||||
import com.songoda.core.hooks.stackers.StackMob;
|
||||
import com.songoda.core.hooks.stackers.Stacker;
|
||||
import com.songoda.core.hooks.stackers.UltimateStacker;
|
||||
import com.songoda.core.hooks.stackers.WildStacker;
|
||||
import com.songoda.ultimateclaims.UltimateClaims;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
@ -39,6 +44,10 @@ public final class PluginHook<T extends Class> {
|
||||
public static final PluginHook HOLO_HOLOGRAMS = new PluginHook(Holograms.class, "Holograms", HologramsHolograms.class);
|
||||
public static final PluginHook HOLO_CMI = new PluginHook(Holograms.class, "CMI", CMIHolograms.class);
|
||||
public static final PluginHook LOG_CORE_PROTECT = new PluginHook(Log.class, "CoreProtect", CoreProtectLog.class);
|
||||
public static final PluginHook PROTECTION_GRIEFPREVENTION = new PluginHook(Protection.class, "GriefPrevention", GriefPreventionProtection.class);
|
||||
public static final PluginHook PROTECTION_LANDS = new PluginHook(Protection.class, "Lands", LandsProtection.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", UltimateClaims.class);
|
||||
|
||||
/******* Start Manager stuff *******/
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.songoda.core.hooks;
|
||||
|
||||
import com.songoda.core.hooks.protection.Protection;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ProtectionManager {
|
||||
|
||||
private static final HookManager<Protection> manager = new HookManager(Protection.class);
|
||||
|
||||
/**
|
||||
* Load all supported protection plugins.<br/>
|
||||
* Note: This method should be called in your plugin's onEnable() section
|
||||
*
|
||||
* @param plugin plugin that will be using the protection hooks.
|
||||
*/
|
||||
public static void load(Plugin plugin) {
|
||||
manager.load(plugin);
|
||||
}
|
||||
|
||||
public static HookManager getManager() {
|
||||
return manager;
|
||||
}
|
||||
|
||||
public static boolean canPlace(Player player, Location location) {
|
||||
return manager.getRegisteredHooks().stream().allMatch(protection -> protection.canPlace(player, location));
|
||||
}
|
||||
|
||||
public static boolean canBreak(Player player, Location location) {
|
||||
return manager.getRegisteredHooks().stream().allMatch(protection -> protection.canBreak(player, location));
|
||||
}
|
||||
|
||||
public static boolean canInteract(Player player, Location location) {
|
||||
return manager.getRegisteredHooks().stream().allMatch(protection -> protection.canInteract(player, location));
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.songoda.core.hooks.protection;
|
||||
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.DataStore;
|
||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class GriefPreventionProtection extends Protection {
|
||||
|
||||
private final DataStore dataStore;
|
||||
|
||||
public GriefPreventionProtection(Plugin plugin) {
|
||||
super(plugin);
|
||||
this.dataStore = GriefPrevention.instance.dataStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Player player, Location location) {
|
||||
return getClaim(location).allowBuild(player, location.getBlock().getType()) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Player player, Location location) {
|
||||
return getClaim(location).allowBreak(player, location.getBlock().getType()) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Location location) {
|
||||
return getClaim(location).allowContainers(player) == null;
|
||||
}
|
||||
|
||||
private Claim getClaim(Location location) {
|
||||
return dataStore.getClaimAt(location, true, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "GriefPrevention";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return GriefPrevention.instance != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.songoda.core.hooks.protection;
|
||||
|
||||
import me.angeschossen.lands.api.integration.LandsIntegration;
|
||||
import me.angeschossen.lands.api.role.enums.RoleSetting;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class LandsProtection extends Protection {
|
||||
|
||||
private final LandsIntegration landsIntegration;
|
||||
|
||||
public LandsProtection(Plugin plugin) {
|
||||
super(plugin);
|
||||
this.landsIntegration = new LandsIntegration(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Player player, Location location) {
|
||||
return landsIntegration.getAreaByLoc(location).canSetting(player, RoleSetting.BLOCK_PLACE, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Player player, Location location) {
|
||||
return landsIntegration.getAreaByLoc(location).canSetting(player, RoleSetting.BLOCK_BREAK, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Location location) {
|
||||
return landsIntegration.getAreaByLoc(location).canSetting(player, RoleSetting.INTERACT_CONTAINER, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Lands";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return landsIntegration != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.songoda.core.hooks.protection;
|
||||
|
||||
import com.songoda.core.hooks.Hook;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public abstract class Protection implements Hook {
|
||||
|
||||
protected final Plugin plugin;
|
||||
|
||||
public Protection(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public abstract boolean canPlace(Player player, Location location);
|
||||
|
||||
public abstract boolean canBreak(Player player, Location location);
|
||||
|
||||
public abstract boolean canInteract(Player player, Location location);
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.songoda.core.hooks.protection;
|
||||
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.API.RedProtectAPI;
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.RedProtect;
|
||||
import br.net.fabiozumbi12.RedProtect.Bukkit.Region;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class RedProtectProtection extends Protection {
|
||||
|
||||
private final RedProtectAPI api;
|
||||
|
||||
public RedProtectProtection(Plugin plugin) {
|
||||
super(plugin);
|
||||
this.api = RedProtect.get().getAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Player player, Location location) {
|
||||
Region region = api.getRegion(location);
|
||||
if (region == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return region.canBuild(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Player player, Location location) {
|
||||
Region region = api.getRegion(location);
|
||||
if (region == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return region.canBuild(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Location location) {
|
||||
Region region = api.getRegion(location);
|
||||
if (region == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return region.canChest(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "RedProtect";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return api != null;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.songoda.core.hooks.protection;
|
||||
|
||||
import com.songoda.ultimateclaims.UltimateClaims;
|
||||
import com.songoda.ultimateclaims.member.ClaimPerm;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class UltimateClaimsProtection extends Protection {
|
||||
|
||||
private final UltimateClaims instance;
|
||||
|
||||
public UltimateClaimsProtection(Plugin plugin) {
|
||||
super(plugin);
|
||||
instance = UltimateClaims.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Player player, Location location) {
|
||||
return instance.getClaimManager().getClaim(location.getChunk()).playerHasPerms(player, ClaimPerm.PLACE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Player player, Location location) {
|
||||
return instance.getClaimManager().getClaim(location.getChunk()).playerHasPerms(player, ClaimPerm.BREAK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInteract(Player player, Location location) {
|
||||
return instance.getClaimManager().getClaim(location.getChunk()).playerHasPerms(player, ClaimPerm.INTERACT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "UltimateClaims";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return instance != null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user