Search in sources :

Example 1 with Vector3i

use of com.griefdefender.lib.flowpowered.math.vector.Vector3i 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 Vector3i

use of com.griefdefender.lib.flowpowered.math.vector.Vector3i 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 Vector3i

use of com.griefdefender.lib.flowpowered.math.vector.Vector3i 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 Vector3i

use of com.griefdefender.lib.flowpowered.math.vector.Vector3i in project BanFromClaim by Baktus79.

the class BfclistCommandGD 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();
    if (args.length != 0) {
        if (isInt(args[0])) {
            this.number = Integer.parseInt(args[0]);
            this.countTo = 5 * number;
            this.countFrom = 5 * number - 5;
        } else {
            MessageHandler.sendMessage(player, Messages.UNVALID_NUMBER);
            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;
    }
    int totalPage = 1;
    if (!allowBan) {
        MessageHandler.sendMessage(player, Messages.NO_ACCESS);
        return true;
    } else {
        MessageHandler.sendMessage(player, Messages.placeholders(Messages.LIST_HEADER, null, player.getDisplayName(), claim.getOwnerName()));
        if (claimData.isAllBanned(claim.getUniqueId().toString())) {
            MessageHandler.sendMessage(player, Messages.LIST_BAN_ALL);
            return true;
        }
        if (listPlayers(claim.getUniqueId().toString()) == null) {
            MessageHandler.sendMessage(player, Messages.placeholders(Messages.LIST_EMPTY, null, player.getDisplayName(), claim.getOwnerName()));
            return true;
        } else {
            totalPage = listPlayers(claim.getUniqueId().toString()).size() / 5 + 1;
            for (int i = 0; i < listPlayers(claim.getUniqueId().toString()).toArray().length; i++) {
                if (this.number > totalPage || this.number == 0) {
                    this.countTo = 5 * totalPage;
                    this.countFrom = 5 * totalPage - 5;
                    this.number = totalPage;
                }
                if (i >= this.countFrom) {
                    final String bp = (String) listPlayers(claim.getUniqueId().toString()).toArray()[i];
                    final OfflinePlayer bannedPlayer = Bukkit.getOfflinePlayer(UUID.fromString(bp));
                    MessageHandler.sendMessage(player, "&6" + bannedPlayer.getName());
                    if (i == this.countTo) {
                        MessageHandler.sendMessage(player, "");
                        MessageHandler.sendMessage(player, "&e<--- [&6" + this.number + "\\" + totalPage + "&e] --->");
                        break;
                    }
                    continue;
                }
            }
            if (this.number == totalPage) {
                MessageHandler.sendMessage(player, "");
                MessageHandler.sendMessage(player, "&e<--- [&6" + totalPage + "\\" + totalPage + "&e] --->");
            }
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) ClaimData(no.vestlandetmc.BanFromClaim.config.ClaimData) 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 5 with Vector3i

use of com.griefdefender.lib.flowpowered.math.vector.Vector3i in project BanFromClaim by Baktus79.

the class KfcCommandGD 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 Player kickedPlayer = Bukkit.getPlayer(args[0]);
    final boolean isManager = claim.getUserTrusts(TrustTypes.MANAGER).contains(player.getUniqueId());
    final boolean isOwner = claim.getOwnerUniqueId().equals(player.getUniqueId());
    boolean allowKick = false;
    if (isOwner || isManager) {
        allowKick = true;
    } else if (player.hasPermission("bfc.admin")) {
        allowKick = true;
    }
    if (kickedPlayer == null) {
        MessageHandler.sendMessage(player, Messages.placeholders(Messages.UNVALID_PLAYERNAME, args[0], player.getDisplayName(), null));
        return true;
    } else if (kickedPlayer == player) {
        MessageHandler.sendMessage(player, Messages.KICK_SELF);
        return true;
    } else if (kickedPlayer.getName().equals(claim.getOwnerName())) {
        MessageHandler.sendMessage(player, Messages.KICK_OWNER);
        return true;
    }
    if (kickedPlayer.hasPermission("bfc.bypass")) {
        MessageHandler.sendMessage(player, Messages.placeholders(Messages.PROTECTED, kickedPlayer.getDisplayName(), null, null));
        return true;
    }
    if (!allowKick) {
        MessageHandler.sendMessage(player, Messages.NO_ACCESS);
        return true;
    } else {
        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());
        final String claimOwner = claim.getOwnerName();
        final Location kickedLoc = kickedPlayer.getLocation();
        final Vector3i kickedVec = Vector3i.from(kickedLoc.getBlockX(), kickedLoc.getBlockY(), kickedLoc.getBlockZ());
        if (claim.contains(kickedVec)) {
            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) {
                        kickedPlayer.teleport(kickedLoc.getWorld().getSpawnLocation());
                    } else {
                        kickedPlayer.teleport(Config.SAFE_LOCATION);
                    }
                } else {
                    kickedPlayer.teleport(randomCircumferenceRadiusLoc);
                }
                MessageHandler.sendMessage(kickedPlayer, Messages.placeholders(Messages.KICKED_TARGET, kickedPlayer.getName(), player.getDisplayName(), claimOwner));
            }));
        }
    }
    MessageHandler.sendMessage(player, Messages.placeholders(Messages.KICKED, kickedPlayer.getName(), null, null));
    return true;
}
Also used : MessageHandler(no.vestlandetmc.BanFromClaim.handler.MessageHandler) CommandSender(org.bukkit.command.CommandSender) 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) 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) LocationFinder(no.vestlandetmc.BanFromClaim.handler.LocationFinder) Vector3i(com.griefdefender.lib.flowpowered.math.vector.Vector3i) Claim(com.griefdefender.api.claim.Claim) Location(org.bukkit.Location) Core(com.griefdefender.api.Core)

Aggregations

Vector3i (com.griefdefender.lib.flowpowered.math.vector.Vector3i)8 Claim (com.griefdefender.api.claim.Claim)7 Core (com.griefdefender.api.Core)6 Location (org.bukkit.Location)6 Player (org.bukkit.entity.Player)6 ClaimData (no.vestlandetmc.BanFromClaim.config.ClaimData)4 OfflinePlayer (org.bukkit.OfflinePlayer)3 GriefDefender (com.griefdefender.api.GriefDefender)2 TrustTypes (com.griefdefender.api.claim.TrustTypes)2 UUID (java.util.UUID)2 BfcPlugin (no.vestlandetmc.BanFromClaim.BfcPlugin)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 World (org.bukkit.World)2 Command (org.bukkit.command.Command)2 CommandExecutor (org.bukkit.command.CommandExecutor)2 CommandSender (org.bukkit.command.CommandSender)2