use of com.griefdefender.api.claim.ClaimResult in project GDHooks by bloodmc.
the class CommandClanTrust method execute.
@CommandCompletion("@gdclans @gdtrusttypes @gddummy")
@CommandAlias("clantrust")
@Description("%clan-trust")
@Syntax("<clan> [<accessor|builder|container|manager|resident>]")
@Subcommand("clan trust")
public void execute(CommandSender sender, String clanTag, @Optional String type, @Optional String identifier) {
TrustType trustType = null;
final Audience audience = GriefDefender.getAudienceProvider().getSender(sender);
if (type == null) {
trustType = TrustTypes.BUILDER;
} else {
trustType = HooksUtil.getTrustType(type);
if (trustType == null) {
audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_INVALID));
return;
}
}
final Clan clan = GDHooks.getInstance().getClanProvider().getClan(clanTag);
if (clan == null) {
audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.COMMAND_INVALID_CLAN, ImmutableMap.of("clan", clanTag)));
return;
}
final CommandResult result = GriefDefender.getCore().canUseCommand(sender, TrustTypes.MANAGER, identifier);
if (!result.successful()) {
if (result.getClaim() != null) {
final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.PERMISSION_TRUST, ImmutableMap.of("owner", result.getClaim().getOwnerDisplayName()));
audience.sendMessage(message);
} else {
audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.PERMISSION_COMMAND_TRUST));
}
return;
}
final Claim claim = result.getClaim();
if (!claim.isAdminClaim() && !claim.isTown() && trustType == TrustTypes.RESIDENT) {
audience.sendMessage(Component.text("Resident trust not allowed in this claim type."));
return;
}
if (claim.isClanTrusted(clan, trustType)) {
final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_ALREADY_HAS, ImmutableMap.of("target", clan.getTag(), "type", trustType.getName()));
audience.sendMessage(message);
return;
}
GriefDefender.getEventManager().getCauseStackManager().pushCause(sender);
final ClaimResult claimResult = claim.addClanTrust(clanTag, trustType);
GriefDefender.getEventManager().getCauseStackManager().popCause();
if (!claimResult.successful()) {
audience.sendMessage(claimResult.getMessage().orElse(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_PLUGIN_CANCEL, ImmutableMap.of("target", clan.getTag()))));
return;
}
final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_GRANT, ImmutableMap.of("target", clan.getTag(), "type", trustType.getName()));
audience.sendMessage(message);
}
use of com.griefdefender.api.claim.ClaimResult in project GDHooks by bloodmc.
the class CommandClanUntrust method execute.
@CommandCompletion("@gdclans @gdtrusttypes @gddummy")
@CommandAlias("clanuntrust")
@Description("%clan-untrust")
@Syntax("<clan> [<accessor|builder|container|manager|resident>]")
@Subcommand("clan untrust")
public void execute(CommandSender sender, String clanTag, @Optional String type, @Optional String identifier) {
TrustType trustType = null;
final Audience audience = GriefDefender.getAudienceProvider().getSender(sender);
if (type == null) {
trustType = TrustTypes.NONE;
} else {
trustType = HooksUtil.getTrustType(type);
if (trustType == null) {
audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_INVALID));
return;
}
}
final Clan clan = GDHooks.getInstance().getClanProvider().getClan(clanTag);
if (clan == null) {
audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.COMMAND_INVALID_CLAN, ImmutableMap.of("clan", clanTag)));
return;
}
final CommandResult result = GriefDefender.getCore().canUseCommand(sender, TrustTypes.MANAGER, identifier);
if (!result.successful()) {
if (result.getClaim() != null) {
final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.PERMISSION_TRUST, ImmutableMap.of("owner", result.getClaim().getOwnerDisplayName()));
audience.sendMessage(message);
} else {
audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.PERMISSION_COMMAND_TRUST));
}
return;
}
final Claim claim = result.getClaim();
GriefDefender.getEventManager().getCauseStackManager().pushCause(sender);
final ClaimResult claimResult = claim.removeClanTrust(clanTag, trustType);
GriefDefender.getEventManager().getCauseStackManager().popCause();
if (!claimResult.successful()) {
audience.sendMessage(claimResult.getMessage().orElse(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_PLUGIN_CANCEL, ImmutableMap.of("target", clan.getTag()))));
return;
}
final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.UNTRUST_INDIVIDUAL_SINGLE_CLAIM, ImmutableMap.of("target", clan.getTag()));
audience.sendMessage(message);
}
use of com.griefdefender.api.claim.ClaimResult in project GDHooks by bloodmc.
the class OreRegeneratorProvider method onCreateRegion.
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCreateRegion(RegionCreateEvent event) {
final Player player = event.getCreator();
final World world = event.getCreator().getWorld();
final int x1 = event.getLocationOne().getBlockX();
final int x2 = event.getLocationTwo().getBlockX();
final int y1 = event.getLocationOne().getBlockY();
final int y2 = event.getLocationTwo().getBlockY();
final int z1 = event.getLocationOne().getBlockZ();
final int z2 = event.getLocationTwo().getBlockZ();
final Claim currentClaim = GriefDefender.getCore().getClaimAt(event.getLocationOne());
if (currentClaim.isWilderness()) {
final ClaimResult result = Claim.builder().world(world.getUID()).bounds(x1, x2, y1, y2, z1, z2).owner(TEMP_USER_UUID).type(ClaimTypes.BASIC).cuboid(true).build();
if (!result.successful()) {
event.setCancelled(true);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cUnable to create ore region. Reason: " + result.getResultType().name()));
}
return;
} else {
if (!currentClaim.isUserTrusted(player.getUniqueId(), TrustTypes.BUILDER)) {
event.setCancelled(true);
event.setReason(ChatColor.translateAlternateColorCodes('&', "&cYou do not have " + currentClaim.getOwnerName() + "'s permission to build here."));
return;
}
final ClaimResult result = Claim.builder().world(world.getUID()).bounds(x1, x2, y1, y2, z1, z2).owner(TEMP_USER_UUID).type(ClaimTypes.SUBDIVISION).cuboid(true).parent(currentClaim).build();
if (!result.successful()) {
event.setCancelled(true);
player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cUnable to create ore region. Reason: " + result.getResultType().name()));
}
}
}
use of com.griefdefender.api.claim.ClaimResult in project GDHooks by bloodmc.
the class TownyProvider method canCreateTown.
private boolean canCreateTown(World world, int townBlockX, int townBlockZ) {
final int sx = townBlockX << 4;
final int sz = townBlockZ << 4;
final int bx = sx + 15;
final int bz = sz + 15;
final Vector3i lesserBoundary = new Vector3i(sx, -64, sz);
final Vector3i greaterBoundary = new Vector3i(bx, 319, bz);
final ClaimResult result = GriefDefender.getRegistry().createBuilder(Claim.Builder.class).bounds(lesserBoundary, greaterBoundary).cuboid(false).owner(TEMP_USER_UUID).type(ClaimTypes.BASIC).world(world.getUID()).build();
if (!result.successful()) {
return false;
}
return true;
}
Aggregations