Search in sources :

Example 1 with Core

use of com.griefdefender.api.Core in project BanFromClaim by Baktus79.

the class BfcAllCommandGD method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player)) {
        MessageHandler.sendConsole("&cThis command can only be used in-game.");
        return true;
    }
    final Player player = (Player) sender;
    final Location loc = player.getLocation();
    final Vector3i vector = Vector3i.from(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    final Core gd = GriefDefender.getCore();
    final Claim claim = gd.getClaimManager(loc.getWorld().getUID()).getClaimAt(vector);
    final ClaimData claimData = new ClaimData();
    final boolean isManager = claim.getUserTrusts(TrustTypes.MANAGER).contains(player.getUniqueId());
    final boolean isOwner = claim.getOwnerUniqueId().equals(player.getUniqueId());
    boolean allowBan = false;
    if (claim.isWilderness()) {
        MessageHandler.sendMessage(player, Messages.OUTSIDE_CLAIM);
        return true;
    }
    if (isOwner || isManager) {
        allowBan = true;
    } else if (player.hasPermission("bfc.admin")) {
        allowBan = true;
    }
    if (allowBan) {
        claimData.banAll(claim.getUniqueId().toString());
        if (claimData.isAllBanned(claim.getUniqueId().toString())) {
            MessageHandler.sendMessage(player, Messages.BAN_ALL);
        } else {
            MessageHandler.sendMessage(player, Messages.UNBAN_ALL);
        }
    } else {
        MessageHandler.sendMessage(player, Messages.NO_ACCESS);
        return true;
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ClaimData(no.vestlandetmc.BanFromClaim.config.ClaimData) Vector3i(com.griefdefender.lib.flowpowered.math.vector.Vector3i) Claim(com.griefdefender.api.claim.Claim) Location(org.bukkit.Location) Core(com.griefdefender.api.Core)

Example 2 with Core

use of com.griefdefender.api.Core in project BanFromClaim by Baktus79.

the class BfcCommandGD method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player)) {
        MessageHandler.sendConsole("&cThis command can only be used in-game.");
        return true;
    }
    final Player player = (Player) sender;
    final Location loc = player.getLocation();
    final Vector3i vector = Vector3i.from(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    final Core gd = GriefDefender.getCore();
    final Claim claim = gd.getClaimManager(loc.getWorld().getUID()).getClaimAt(vector);
    if (args.length == 0) {
        MessageHandler.sendMessage(player, Messages.NO_ARGUMENTS);
        return true;
    }
    if (claim.isWilderness()) {
        MessageHandler.sendMessage(player, Messages.OUTSIDE_CLAIM);
        return true;
    }
    @SuppressWarnings("deprecation") final OfflinePlayer bannedPlayer = Bukkit.getOfflinePlayer(args[0]);
    final boolean isManager = claim.getUserTrusts(TrustTypes.MANAGER).contains(player.getUniqueId());
    final boolean isOwner = claim.getOwnerUniqueId().equals(player.getUniqueId());
    boolean allowBan = false;
    if (isOwner || isManager) {
        allowBan = true;
    } else if (player.hasPermission("bfc.admin")) {
        allowBan = true;
    }
    if (!bannedPlayer.hasPlayedBefore()) {
        MessageHandler.sendMessage(player, Messages.placeholders(Messages.UNVALID_PLAYERNAME, args[0], player.getDisplayName(), null));
        return true;
    } else if (bannedPlayer == player) {
        MessageHandler.sendMessage(player, Messages.BAN_SELF);
        return true;
    } else if (bannedPlayer.getName().equals(claim.getOwnerName())) {
        MessageHandler.sendMessage(player, Messages.BAN_OWNER);
        return true;
    }
    if (bannedPlayer.isOnline()) {
        if (bannedPlayer.getPlayer().hasPermission("bfc.bypass")) {
            MessageHandler.sendMessage(player, Messages.placeholders(Messages.PROTECTED, bannedPlayer.getPlayer().getDisplayName(), null, null));
            return true;
        }
    }
    if (!allowBan) {
        MessageHandler.sendMessage(player, Messages.NO_ACCESS);
        return true;
    } else {
        final String claimOwner = claim.getOwnerName();
        final int sizeRadius = Math.max(claim.getLength(), claim.getWidth());
        final Location greaterCorner = new Location(Bukkit.getWorld(claim.getWorldUniqueId()), claim.getGreaterBoundaryCorner().getX(), 64D, claim.getGreaterBoundaryCorner().getZ());
        final Location lesserCorner = new Location(Bukkit.getWorld(claim.getWorldUniqueId()), claim.getLesserBoundaryCorner().getX(), 64D, claim.getLesserBoundaryCorner().getZ());
        if (setClaimData(player, claim.getUniqueId().toString(), bannedPlayer.getUniqueId().toString(), true)) {
            if (bannedPlayer.isOnline()) {
                final Location bannedLoc = bannedPlayer.getPlayer().getLocation();
                final Vector3i bannedVec = Vector3i.from(bannedLoc.getBlockX(), bannedLoc.getBlockY(), bannedLoc.getBlockZ());
                if (claim.contains(bannedVec)) {
                    final LocationFinder lf = new LocationFinder(greaterCorner, lesserCorner, claim.getWorldUniqueId(), sizeRadius);
                    Bukkit.getScheduler().runTaskAsynchronously(BfcPlugin.getInstance(), () -> lf.IterateCircumferencesGD(randomCircumferenceRadiusLoc -> {
                        if (randomCircumferenceRadiusLoc == null) {
                            if (Config.SAFE_LOCATION == null) {
                                bannedPlayer.getPlayer().teleport(bannedLoc.getWorld().getSpawnLocation());
                            } else {
                                bannedPlayer.getPlayer().teleport(Config.SAFE_LOCATION);
                            }
                        } else {
                            bannedPlayer.getPlayer().teleport(randomCircumferenceRadiusLoc);
                        }
                        MessageHandler.sendMessage(bannedPlayer.getPlayer(), Messages.placeholders(Messages.BANNED_TARGET, bannedPlayer.getName(), player.getDisplayName(), claimOwner));
                    }));
                }
            }
            MessageHandler.sendMessage(player, Messages.placeholders(Messages.BANNED, bannedPlayer.getName(), null, null));
        } else {
            MessageHandler.sendMessage(player, Messages.ALREADY_BANNED);
        }
    }
    return true;
}
Also used : MessageHandler(no.vestlandetmc.BanFromClaim.handler.MessageHandler) CommandSender(org.bukkit.command.CommandSender) ClaimData(no.vestlandetmc.BanFromClaim.config.ClaimData) BfcPlugin(no.vestlandetmc.BanFromClaim.BfcPlugin) Messages(no.vestlandetmc.BanFromClaim.config.Messages) Config(no.vestlandetmc.BanFromClaim.config.Config) Claim(com.griefdefender.api.claim.Claim) LocationFinder(no.vestlandetmc.BanFromClaim.handler.LocationFinder) Player(org.bukkit.entity.Player) GriefDefender(com.griefdefender.api.GriefDefender) CommandExecutor(org.bukkit.command.CommandExecutor) OfflinePlayer(org.bukkit.OfflinePlayer) Vector3i(com.griefdefender.lib.flowpowered.math.vector.Vector3i) TrustTypes(com.griefdefender.api.claim.TrustTypes) Location(org.bukkit.Location) Command(org.bukkit.command.Command) Core(com.griefdefender.api.Core) Bukkit(org.bukkit.Bukkit) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) LocationFinder(no.vestlandetmc.BanFromClaim.handler.LocationFinder) Vector3i(com.griefdefender.lib.flowpowered.math.vector.Vector3i) OfflinePlayer(org.bukkit.OfflinePlayer) Claim(com.griefdefender.api.claim.Claim) Location(org.bukkit.Location) Core(com.griefdefender.api.Core)

Example 3 with Core

use of com.griefdefender.api.Core in project BanFromClaim by Baktus79.

the class UnbfcCommandGD method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!(sender instanceof Player)) {
        MessageHandler.sendConsole("&cThis command can only be used in-game.");
        return true;
    }
    final Player player = (Player) sender;
    final Location loc = player.getLocation();
    final Vector3i vector = Vector3i.from(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
    final Core gd = GriefDefender.getCore();
    final Claim claim = gd.getClaimManager(loc.getWorld().getUID()).getClaimAt(vector);
    if (args.length == 0) {
        MessageHandler.sendMessage(player, Messages.NO_ARGUMENTS);
        return true;
    }
    if (claim.isWilderness()) {
        MessageHandler.sendMessage(player, Messages.OUTSIDE_CLAIM);
        return true;
    }
    final boolean isManager = claim.getUserTrusts(TrustTypes.MANAGER).contains(player.getUniqueId());
    final boolean isOwner = claim.getOwnerUniqueId().equals(player.getUniqueId());
    boolean allowBan = false;
    if (isOwner || isManager) {
        allowBan = true;
    } else if (player.hasPermission("bfc.admin")) {
        allowBan = true;
    }
    OfflinePlayer bPlayer = null;
    if (!allowBan) {
        MessageHandler.sendMessage(player, Messages.NO_ACCESS);
        return true;
    } else {
        final String claimOwner = claim.getOwnerName();
        final String claimID = claim.getUniqueId().toString();
        if (listPlayers(claimID) != null) {
            for (final String bp : listPlayers(claimID)) {
                final OfflinePlayer bannedPlayer = Bukkit.getOfflinePlayer(UUID.fromString(bp));
                if (bannedPlayer.getName().equalsIgnoreCase(args[0])) {
                    bPlayer = bannedPlayer;
                    if (setClaimData(player, claimID, bp, false)) {
                        MessageHandler.sendMessage(player, Messages.placeholders(Messages.UNBANNED, bannedPlayer.getName(), player.getDisplayName(), claimOwner));
                        if (bannedPlayer.isOnline()) {
                            MessageHandler.sendMessage(bannedPlayer.getPlayer(), Messages.placeholders(Messages.UNBANNED_TARGET, bannedPlayer.getName(), player.getDisplayName(), claimOwner));
                        }
                        return true;
                    }
                }
            }
        }
    }
    if (bPlayer == null) {
        MessageHandler.sendMessage(player, Messages.placeholders(Messages.NOT_BANNED, args[0], player.getDisplayName(), null));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) Vector3i(com.griefdefender.lib.flowpowered.math.vector.Vector3i) OfflinePlayer(org.bukkit.OfflinePlayer) Claim(com.griefdefender.api.claim.Claim) Location(org.bukkit.Location) Core(com.griefdefender.api.Core)

Example 4 with Core

use of com.griefdefender.api.Core in project CombatLogX by SirBlobman.

the class GriefDefenderRegionHandler method isSafeZone.

@Override
public boolean isSafeZone(Player player, Location location, TagType tagType) {
    if (tagType != TagType.PLAYER) {
        return false;
    }
    Claim claim = getClaimAt(location);
    if (claim == null) {
        return false;
    }
    UUID playerId = player.getUniqueId();
    Core core = GriefDefender.getCore();
    User user = core.getUser(playerId);
    Set<Context> contexts = new HashSet<>();
    TypeToken<Tristate> typeTokenTristate = TypeToken.get(Tristate.class);
    Tristate activeOptionValue = claim.getActiveOptionValue(typeTokenTristate, Options.PVP, user, contexts);
    return (activeOptionValue != Tristate.TRUE);
}
Also used : Context(com.griefdefender.api.permission.Context) User(com.griefdefender.api.User) Tristate(com.griefdefender.api.Tristate) UUID(java.util.UUID) Claim(com.griefdefender.api.claim.Claim) Core(com.griefdefender.api.Core) HashSet(java.util.HashSet)

Example 5 with Core

use of com.griefdefender.api.Core in project CombatLogX by SirBlobman.

the class GriefDefenderRegionHandler method getClaimAt.

private Claim getClaimAt(Location location) {
    World world = location.getWorld();
    if (world == null) {
        return null;
    }
    UUID worldId = world.getUID();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();
    Core core = GriefDefender.getCore();
    ClaimManager claimManager = core.getClaimManager(worldId);
    if (claimManager == null) {
        return null;
    }
    return claimManager.getClaimAt(x, y, z);
}
Also used : ClaimManager(com.griefdefender.api.claim.ClaimManager) World(org.bukkit.World) UUID(java.util.UUID) Core(com.griefdefender.api.Core)

Aggregations

Core (com.griefdefender.api.Core)9 Claim (com.griefdefender.api.claim.Claim)7 Location (org.bukkit.Location)7 Vector3i (com.griefdefender.lib.flowpowered.math.vector.Vector3i)6 Player (org.bukkit.entity.Player)6 ClaimData (no.vestlandetmc.BanFromClaim.config.ClaimData)4 UUID (java.util.UUID)3 BfcPlugin (no.vestlandetmc.BanFromClaim.BfcPlugin)3 OfflinePlayer (org.bukkit.OfflinePlayer)3 World (org.bukkit.World)3 GriefDefender (com.griefdefender.api.GriefDefender)2 TrustTypes (com.griefdefender.api.claim.TrustTypes)2 Config (no.vestlandetmc.BanFromClaim.config.Config)2 Messages (no.vestlandetmc.BanFromClaim.config.Messages)2 LocationFinder (no.vestlandetmc.BanFromClaim.handler.LocationFinder)2 MessageHandler (no.vestlandetmc.BanFromClaim.handler.MessageHandler)2 Bukkit (org.bukkit.Bukkit)2 Command (org.bukkit.command.Command)2 CommandExecutor (org.bukkit.command.CommandExecutor)2 CommandSender (org.bukkit.command.CommandSender)2