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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations