Moved Anticheat + Antigrief integrations into eco-util
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package com.willfp.eco.util.integrations.anticheat;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Utility class for Anticheat Integrations
|
||||
*/
|
||||
public class AnticheatManager {
|
||||
private static final Set<AnticheatWrapper> anticheats = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new anticheat
|
||||
*
|
||||
* @param anticheat The anticheat to register
|
||||
*/
|
||||
public static void register(AnticheatWrapper anticheat) {
|
||||
if (anticheat instanceof Listener) {
|
||||
AbstractEcoPlugin.getInstance().getEventManager().registerEvents((Listener) anticheat);
|
||||
}
|
||||
anticheats.add(anticheat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exempt a player from triggering anticheats
|
||||
*
|
||||
* @param player The player to exempt
|
||||
*/
|
||||
public static void exemptPlayer(Player player) {
|
||||
anticheats.forEach(anticheat -> anticheat.exempt(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unexempt a player from triggering anticheats
|
||||
* This is ran a tick after it is called to ensure that there are no event timing conflicts
|
||||
*
|
||||
* @param player The player to remove the exemption
|
||||
*/
|
||||
public static void unexemptPlayer(Player player) {
|
||||
AbstractEcoPlugin.getInstance().getScheduler().runLater(() -> {
|
||||
anticheats.forEach(anticheat -> anticheat.unexempt(player));
|
||||
}, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.willfp.eco.util.integrations.anticheat;
|
||||
|
||||
import com.willfp.eco.util.integrations.Integration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Interface for anticheat integrations
|
||||
*/
|
||||
public interface AnticheatWrapper extends Integration {
|
||||
/**
|
||||
* Exempt a player from checks
|
||||
*
|
||||
* @param player The player to exempt
|
||||
*/
|
||||
void exempt(Player player);
|
||||
|
||||
/**
|
||||
* Unexempt a player from checks
|
||||
*
|
||||
* @param player The player to unexempt
|
||||
*/
|
||||
void unexempt(Player player);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||
import me.konsolas.aac.api.AACAPI;
|
||||
import me.konsolas.aac.api.AACExemption;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class AnticheatAAC implements AnticheatWrapper, Listener {
|
||||
private final AACExemption ecoEnchantsExemption = new AACExemption("EcoEnchants");
|
||||
private final AACAPI api = Bukkit.getServicesManager().load(AACAPI.class);
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "AAC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exempt(Player player) {
|
||||
api.addExemption(player, ecoEnchantsExemption);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unexempt(Player player) {
|
||||
api.removeExemption(player, ecoEnchantsExemption);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||
import me.rerere.matrix.api.events.PlayerViolationEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AnticheatMatrix implements AnticheatWrapper, Listener {
|
||||
private final Set<UUID> exempt = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "Matrix";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exempt(Player player) {
|
||||
this.exempt.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unexempt(Player player) {
|
||||
this.exempt.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
private void onViolate(PlayerViolationEvent event) {
|
||||
if (!exempt.contains(event.getPlayer().getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AnticheatNCP implements AnticheatWrapper {
|
||||
private final Set<UUID> exempt = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "NCP";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exempt(Player player) {
|
||||
if (!NCPExemptionManager.isExempted(player, CheckType.ALL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (exempt.add(player.getUniqueId())) {
|
||||
NCPExemptionManager.exemptPermanently(player, CheckType.ALL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unexempt(Player player) {
|
||||
if (exempt.remove(player.getUniqueId())) {
|
||||
NCPExemptionManager.unexempt(player, CheckType.ALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.util.integrations.anticheat.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatWrapper;
|
||||
import me.vagdedes.spartan.api.PlayerViolationEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AnticheatSpartan implements AnticheatWrapper, Listener {
|
||||
private final Set<UUID> exempt = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "Spartan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exempt(Player player) {
|
||||
this.exempt.add(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unexempt(Player player) {
|
||||
this.exempt.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
private void onViolate(PlayerViolationEvent event) {
|
||||
if (!exempt.contains(event.getPlayer().getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.willfp.eco.util.integrations.antigrief;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class AntigriefManager {
|
||||
private static final Set<AntigriefWrapper> antigriefs = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Register a new AntiGrief/Land Management integration
|
||||
*
|
||||
* @param antigrief The integration to register
|
||||
*/
|
||||
public static void register(AntigriefWrapper antigrief) {
|
||||
antigriefs.add(antigrief);
|
||||
}
|
||||
|
||||
/**
|
||||
* Can player break block
|
||||
*
|
||||
* @param player The player
|
||||
* @param block The block
|
||||
* @return If player can break block
|
||||
*/
|
||||
public static boolean canBreakBlock(Player player, Block block) {
|
||||
return antigriefs.stream().allMatch(antigriefWrapper -> antigriefWrapper.canBreakBlock(player, block));
|
||||
}
|
||||
|
||||
/**
|
||||
* Can player create explosion at location
|
||||
*
|
||||
* @param player The player
|
||||
* @param location The location
|
||||
* @return If player can create explosion
|
||||
*/
|
||||
public static boolean canCreateExplosion(Player player, Location location) {
|
||||
return antigriefs.stream().allMatch(antigriefWrapper -> antigriefWrapper.canCreateExplosion(player, location));
|
||||
}
|
||||
|
||||
/**
|
||||
* Can player place block
|
||||
*
|
||||
* @param player The player
|
||||
* @param block The block
|
||||
* @return If player can place block
|
||||
*/
|
||||
public static boolean canPlaceBlock(Player player, Block block) {
|
||||
return antigriefs.stream().allMatch(antigriefWrapper -> antigriefWrapper.canPlaceBlock(player, block));
|
||||
}
|
||||
|
||||
/**
|
||||
* Can player injure living entity
|
||||
*
|
||||
* @param player The player
|
||||
* @param victim The victim
|
||||
* @return If player can injure
|
||||
*/
|
||||
public static boolean canInjure(Player player, LivingEntity victim) {
|
||||
return antigriefs.stream().allMatch(antigriefWrapper -> antigriefWrapper.canInjure(player, victim));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.willfp.eco.util.integrations.antigrief;
|
||||
|
||||
import com.willfp.eco.util.integrations.Integration;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Interface for Antigrief integrations
|
||||
*/
|
||||
public interface AntigriefWrapper extends Integration {
|
||||
/**
|
||||
* Can player break block
|
||||
*
|
||||
* @param player The player
|
||||
* @param block The block
|
||||
* @return If player cna break block
|
||||
*/
|
||||
boolean canBreakBlock(Player player, Block block);
|
||||
|
||||
/**
|
||||
* Can player create explosion at location
|
||||
*
|
||||
* @param player The player
|
||||
* @param location The location
|
||||
* @return If player can create explosion
|
||||
*/
|
||||
boolean canCreateExplosion(Player player, Location location);
|
||||
|
||||
/**
|
||||
* Can player place block
|
||||
*
|
||||
* @param player The player
|
||||
* @param block The block
|
||||
* @return If player can place block
|
||||
*/
|
||||
boolean canPlaceBlock(Player player, Block block);
|
||||
|
||||
/**
|
||||
* Can player injure living entity
|
||||
*
|
||||
* @param player The player
|
||||
* @param victim The victim
|
||||
* @return If player can injure
|
||||
*/
|
||||
boolean canInjure(Player player, LivingEntity victim);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
|
||||
import com.massivecraft.factions.Board;
|
||||
import com.massivecraft.factions.FLocation;
|
||||
import com.massivecraft.factions.FPlayer;
|
||||
import com.massivecraft.factions.FPlayers;
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.perms.PermissibleAction;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AntigriefFactionsUUID implements AntigriefWrapper {
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, Block block) {
|
||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
||||
FLocation flocation = new FLocation(block.getLocation());
|
||||
Faction faction = Board.getInstance().getFactionAt(flocation);
|
||||
|
||||
if (!faction.hasAccess(fplayer, PermissibleAction.DESTROY)) {
|
||||
return fplayer.isAdminBypassing();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreateExplosion(Player player, Location location) {
|
||||
FLocation flocation = new FLocation(location);
|
||||
Faction faction = Board.getInstance().getFactionAt(flocation);
|
||||
|
||||
return !faction.noExplosionsInTerritory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Block block) {
|
||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
||||
FLocation flocation = new FLocation(block.getLocation());
|
||||
Faction faction = Board.getInstance().getFactionAt(flocation);
|
||||
|
||||
if (!faction.hasAccess(fplayer, PermissibleAction.BUILD)) {
|
||||
return fplayer.isAdminBypassing();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInjure(Player player, LivingEntity victim) {
|
||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
||||
FLocation flocation = new FLocation(victim.getLocation());
|
||||
Faction faction = Board.getInstance().getFactionAt(flocation);
|
||||
|
||||
if(victim instanceof Player) {
|
||||
if (faction.isPeaceful()) {
|
||||
return fplayer.isAdminBypassing();
|
||||
}
|
||||
} else {
|
||||
if (faction.hasAccess(fplayer, PermissibleAction.DESTROY)) {
|
||||
return fplayer.isAdminBypassing();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "FactionsUUID";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AntigriefGriefPrevention implements AntigriefWrapper {
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, Block block) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(block.getLocation(), false, null);
|
||||
if (claim != null) {
|
||||
return claim.allowBreak(player, block.getType()) == null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreateExplosion(Player player, Location location) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(location, false, null);
|
||||
if (claim != null) {
|
||||
return claim.areExplosivesAllowed;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Block block) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(block.getLocation(), false, null);
|
||||
if (claim != null) {
|
||||
return claim.allowBuild(player, block.getType()) == null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInjure(Player player, LivingEntity victim) {
|
||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(victim.getLocation(), false, null);
|
||||
if(victim instanceof Player) {
|
||||
return claim == null;
|
||||
} else {
|
||||
if (claim != null && claim.ownerID != null) {
|
||||
return claim.ownerID.equals(player.getUniqueId());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "GriefPrevention";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.kingdoms.constants.kingdom.Kingdom;
|
||||
import org.kingdoms.constants.land.Land;
|
||||
import org.kingdoms.managers.PvPManager;
|
||||
import org.kingdoms.managers.land.LandManager;
|
||||
|
||||
public class AntigriefKingdoms implements AntigriefWrapper {
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, Block block) {
|
||||
BlockBreakEvent event = new BlockBreakEvent(block, player);
|
||||
LandManager.onBreak(event);
|
||||
return !event.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreateExplosion(Player player, Location location) {
|
||||
Land land = Land.getLand(location);
|
||||
if (land == null) return true;
|
||||
if(!land.isClaimed()) return true;
|
||||
|
||||
Kingdom kingdom = land.getKingdom();
|
||||
return kingdom.isMember(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Block block) {
|
||||
Block placedOn = block.getRelative(0, -1, 0);
|
||||
BlockPlaceEvent event = new BlockPlaceEvent(block, block.getState(), placedOn, player.getInventory().getItemInMainHand(), player, true, EquipmentSlot.HAND);
|
||||
LandManager.onPlace(event);
|
||||
return !event.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInjure(Player player, LivingEntity victim) {
|
||||
if(victim instanceof Player) {
|
||||
return PvPManager.canFight(player, (Player) victim);
|
||||
} else {
|
||||
Land land = Land.getLand(victim.getLocation());
|
||||
if (land == null) return true;
|
||||
if(!land.isClaimed()) return true;
|
||||
|
||||
Kingdom kingdom = land.getKingdom();
|
||||
return kingdom.isMember(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "Kingdoms";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
|
||||
import com.willfp.eco.util.injection.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import me.angeschossen.lands.api.integration.LandsIntegration;
|
||||
import me.angeschossen.lands.api.land.Area;
|
||||
import me.angeschossen.lands.api.role.enums.RoleSetting;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AntigriefLands extends PluginDependent implements AntigriefWrapper {
|
||||
private final LandsIntegration landsIntegration = new LandsIntegration(this.plugin);
|
||||
|
||||
public AntigriefLands(AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, Block block) {
|
||||
Area area = landsIntegration.getAreaByLoc(block.getLocation());
|
||||
if (area != null) {
|
||||
return area.canSetting(player, RoleSetting.BLOCK_BREAK, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreateExplosion(Player player, Location location) {
|
||||
Area area = landsIntegration.getAreaByLoc(location);
|
||||
if (area != null) {
|
||||
return area.canSetting(player, RoleSetting.BLOCK_IGNITE, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Block block) {
|
||||
Area area = landsIntegration.getAreaByLoc(block.getLocation());
|
||||
if (area != null) {
|
||||
return area.canSetting(player, RoleSetting.BLOCK_PLACE, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInjure(Player player, LivingEntity victim) {
|
||||
Area area = landsIntegration.getAreaByLoc(victim.getLocation());
|
||||
if(victim instanceof Player) {
|
||||
if (area != null) {
|
||||
return area.canSetting(player, RoleSetting.ATTACK_PLAYER, false);
|
||||
}
|
||||
} else {
|
||||
if (area != null) {
|
||||
return area.canSetting(player, RoleSetting.ATTACK_ANIMAL, false);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "Lands";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
|
||||
import com.palmergames.bukkit.towny.object.Town;
|
||||
import com.palmergames.bukkit.towny.object.TownyPermission;
|
||||
import com.palmergames.bukkit.towny.object.WorldCoord;
|
||||
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AntigriefTowny implements AntigriefWrapper {
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, Block block) {
|
||||
return PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getType(), TownyPermission.ActionType.DESTROY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreateExplosion(Player player, Location location) {
|
||||
return PlayerCacheUtil.getCachePermission(player, location, Material.TNT, TownyPermission.ActionType.ITEM_USE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Block block) {
|
||||
return PlayerCacheUtil.getCachePermission(player, block.getLocation(), block.getType(), TownyPermission.ActionType.BUILD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInjure(Player player, LivingEntity victim) {
|
||||
if(victim instanceof Player) {
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(victim.getLocation()).getTownBlock().getTown();
|
||||
return town.isPVP();
|
||||
} catch (Exception ignored) {}
|
||||
} else {
|
||||
try {
|
||||
Town town = WorldCoord.parseWorldCoord(victim.getLocation()).getTownBlock().getTown();
|
||||
return town.hasMobs();
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "Towny";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.willfp.eco.util.integrations.antigrief.plugins;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefWrapper;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AntigriefWorldGuard implements AntigriefWrapper {
|
||||
@Override
|
||||
public boolean canBreakBlock(Player player, Block block) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
|
||||
if (query.queryState(BukkitAdapter.adapt(block.getLocation()), localPlayer, Flags.BUILD) == StateFlag.State.DENY) {
|
||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(block.getWorld()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCreateExplosion(Player player, Location location) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
World world = location.getWorld();
|
||||
Validate.notNull(world, "World cannot be null!");
|
||||
|
||||
if (query.queryState(BukkitAdapter.adapt(location), localPlayer, Flags.OTHER_EXPLOSION) == StateFlag.State.DENY) {
|
||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(world));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceBlock(Player player, Block block) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
|
||||
if (query.queryState(BukkitAdapter.adapt(block.getLocation()), localPlayer, Flags.BLOCK_PLACE) == StateFlag.State.DENY) {
|
||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(block.getWorld()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInjure(Player player, LivingEntity victim) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
RegionQuery query = container.createQuery();
|
||||
|
||||
if(victim instanceof Player) {
|
||||
if (query.queryState(BukkitAdapter.adapt(victim.getLocation()), localPlayer, Flags.PVP) == StateFlag.State.DENY) {
|
||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(player.getWorld()));
|
||||
}
|
||||
} else {
|
||||
if (query.queryState(BukkitAdapter.adapt(victim.getLocation()), localPlayer, Flags.DAMAGE_ANIMALS) == StateFlag.State.DENY) {
|
||||
return WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(localPlayer, BukkitAdapter.adapt(player.getWorld()));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPluginName() {
|
||||
return "WorldGuard";
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,18 @@ import com.willfp.eco.util.events.naturalexpgainevent.NaturalExpGainListeners;
|
||||
import com.willfp.eco.util.extensions.loader.EcoExtensionLoader;
|
||||
import com.willfp.eco.util.extensions.loader.ExtensionLoader;
|
||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.util.integrations.anticheat.plugins.AnticheatAAC;
|
||||
import com.willfp.eco.util.integrations.anticheat.plugins.AnticheatMatrix;
|
||||
import com.willfp.eco.util.integrations.anticheat.plugins.AnticheatNCP;
|
||||
import com.willfp.eco.util.integrations.anticheat.plugins.AnticheatSpartan;
|
||||
import com.willfp.eco.util.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.util.integrations.antigrief.plugins.AntigriefFactionsUUID;
|
||||
import com.willfp.eco.util.integrations.antigrief.plugins.AntigriefGriefPrevention;
|
||||
import com.willfp.eco.util.integrations.antigrief.plugins.AntigriefKingdoms;
|
||||
import com.willfp.eco.util.integrations.antigrief.plugins.AntigriefLands;
|
||||
import com.willfp.eco.util.integrations.antigrief.plugins.AntigriefTowny;
|
||||
import com.willfp.eco.util.integrations.antigrief.plugins.AntigriefWorldGuard;
|
||||
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
@@ -191,6 +203,20 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
|
||||
public final List<IntegrationLoader> getDefaultIntegrations() {
|
||||
integrations.add(new IntegrationLoader("PlaceholderAPI", () -> PlaceholderManager.addIntegration(new PlaceholderIntegrationPAPI(this))));
|
||||
|
||||
// AntiGrief
|
||||
integrations.add(new IntegrationLoader("WorldGuard", () -> AntigriefManager.register(new AntigriefWorldGuard())));
|
||||
integrations.add(new IntegrationLoader("GriefPrevention", () -> AntigriefManager.register(new AntigriefGriefPrevention())));
|
||||
integrations.add(new IntegrationLoader("FactionsUUID", () -> AntigriefManager.register(new AntigriefFactionsUUID())));
|
||||
integrations.add(new IntegrationLoader("Towny", () -> AntigriefManager.register(new AntigriefTowny())));
|
||||
integrations.add(new IntegrationLoader("Lands", () -> AntigriefManager.register(new AntigriefLands(this))));
|
||||
integrations.add(new IntegrationLoader("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms())));
|
||||
|
||||
// Anticheat
|
||||
integrations.add(new IntegrationLoader("AAC", () -> AnticheatManager.register(new AnticheatAAC())));
|
||||
integrations.add(new IntegrationLoader("Matrix", () -> AnticheatManager.register(new AnticheatMatrix())));
|
||||
integrations.add(new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(new AnticheatNCP())));
|
||||
integrations.add(new IntegrationLoader("Spartan", () -> AnticheatManager.register(new AnticheatSpartan())));
|
||||
integrations.addAll(this.getIntegrations());
|
||||
return integrations;
|
||||
}
|
||||
@@ -237,11 +263,11 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
return metadataValueFactory;
|
||||
}
|
||||
|
||||
public ExtensionLoader getExtensionLoader() {
|
||||
public final ExtensionLoader getExtensionLoader() {
|
||||
return extensionLoader;
|
||||
}
|
||||
|
||||
public boolean isOutdated() {
|
||||
public final boolean isOutdated() {
|
||||
return outdated;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user