Java Code Examples for org.spongepowered.api.block.tileentity.Sign#getLocation()

The following examples show how to use org.spongepowered.api.block.tileentity.Sign#getLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EconomyUtil.java    From GriefDefender with MIT License 6 votes vote down vote up
private Consumer<CommandSource> createSellCancelConfirmed(CommandSource src, Claim claim, Sign sign) {
    return confirm -> {
        if (!claim.getEconomyData().isForSale()) {
            return;
        }
        Location<World> location = null;
        if (sign != null) {
            location = sign.getLocation();
        } else {
            final Sign saleSign = SignUtil.getSign(((GDClaim) claim).getWorld(), claim.getEconomyData().getSaleSignPosition());
            if (saleSign != null) {
                location = saleSign.getLocation();
            }
        }
        if (location != null && location.getBlockType() != BlockTypes.AIR) {
            location.setBlockType(BlockTypes.AIR);
            SignUtil.resetSellData(claim);
            claim.getData().save();
            GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().ECONOMY_CLAIM_SALE_CANCELLED);
        }
    };
}
 
Example 2
Source File: SignListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onSignClick(InteractBlockEvent.Secondary event, @Root Player p) {
    if (!event.getTargetBlock().getLocation().isPresent() || !event.getTargetBlock().getLocation().get().getTileEntity().isPresent()) {
        return;
    }
    if (!(event.getTargetBlock().getLocation().get().getTileEntity().get() instanceof Sign)) {
        return;
    }
    Sign sign = (Sign) event.getTargetBlock().getLocation().get().getTileEntity().get();
    for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) {
        if (sign.getSignData().get(0).orElse(Text.of()).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) {
            if (!p.hasPermission(usign.getUsePermission().get())) {
                Messages.send(p, "core.nopermissions");
            }
            SignUseEvent cevent = new SignUseEvent(usign, sign.getLocation(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build()));
            Sponge.getEventManager().post(cevent);
            if (!cevent.isCancelled()) {
                usign.onExecute(p, sign);
            }
        }
    }
}
 
Example 3
Source File: EconomyUtil.java    From GriefDefender with MIT License 4 votes vote down vote up
private Consumer<CommandSource> createRentCancelConfirmed(CommandSource src, Claim claim, Sign sign, boolean addDelinquent) {
    return confirm -> {
        if (!claim.getEconomyData().isForRent() && !claim.getEconomyData().isRented()) {
            return;
        }
        final Player player = (Player) src;
        boolean isRenter = false;
        for (UUID uuid : claim.getEconomyData().getRenters()) {
            if (player.getUniqueId().equals(uuid)) {
                isRenter = true;
                break;
            }
        }
        if (player.getUniqueId().equals(claim.getOwnerUniqueId()) || (claim.isAdminClaim() && !isRenter)) {
                Location<World> location = null;
            if (sign != null) {
                location = sign.getLocation();
            } else {
                final Sign rentSign = SignUtil.getSign(((GDClaim) claim).getWorld(), claim.getEconomyData().getRentSignPosition());
                if (rentSign != null) {
                    location = rentSign.getLocation();
                }
            }
            if (location != null) {
                location.setBlockType(BlockTypes.AIR);
            }
            SignUtil.resetRentData(claim);
            claim.getData().save();
            GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().ECONOMY_CLAIM_RENT_CANCELLED);
        } else if (claim.getEconomyData().isRented()) {
            // reset sign
            claim.getEconomyData().setForRent(true);
            SignUtil.updateSignRentable(claim, sign);
            claim.getEconomyData().setRentSignPosition(null);
            claim.getEconomyData().getRenters().clear();
            claim.getEconomyData().setRentStartDate(null);
            if (addDelinquent) {
                claim.getEconomyData().getDelinquentRenters().add(player.getUniqueId());
            }
            claim.removeUserTrust(player.getUniqueId(), TrustTypes.NONE);
            claim.getData().save();
            final GDPermissionUser owner = PermissionHolderCache.getInstance().getOrCreateUser(claim.getOwnerUniqueId());
            boolean rentRestore = false;
            if (claim.isAdminClaim()) {
                rentRestore = GriefDefenderPlugin.getGlobalConfig().getConfig().economy.rentSchematicRestoreAdmin;
            } else {
                rentRestore = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Boolean.class), owner == null ? GriefDefenderPlugin.DEFAULT_HOLDER : owner, Options.RENT_RESTORE, claim).booleanValue();
            }
            if (rentRestore) {
                // expiration days keep is up
                // restore schematic and remove renter rights
                final ClaimSchematic schematic = claim.getSchematics().get("__rent__");
                if (schematic != null) {
                    if (schematic.apply()) {
                        if (owner != null && owner.getOnlinePlayer() != null) {
                            owner.getOnlinePlayer().sendMessage(Text.of("Claim '" + ((GDClaim) claim).getFriendlyName() + "' has been restored."));
                        }
                    }
                }
            }
            GriefDefenderPlugin.sendMessage(src, MessageCache.getInstance().ECONOMY_CLAIM_RENT_CANCELLED);
        }
    };
}