Search in sources :

Example 1 with Sign

use of org.bukkit.material.Sign in project AreaShop by NLthijs48.

the class AddsignCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (!sender.hasPermission("areashop.addsign")) {
        plugin.message(sender, "addsign-noPermission");
        return;
    }
    if (!(sender instanceof Player)) {
        plugin.message(sender, "cmd-onlyByPlayer");
        return;
    }
    Player player = (Player) sender;
    // Get the sign
    Block block = null;
    BlockIterator blockIterator = new BlockIterator(player, 100);
    while (blockIterator.hasNext() && block == null) {
        Block next = blockIterator.next();
        if (next.getType() != Material.AIR) {
            block = next;
        }
    }
    if (block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
        plugin.message(sender, "addsign-noSign");
        return;
    }
    GeneralRegion region;
    if (args.length > 1) {
        // Get region by argument
        region = plugin.getFileManager().getRegion(args[1]);
        if (region == null) {
            plugin.message(sender, "cmd-notRegistered", args[1]);
            return;
        }
    } else {
        // Get region by sign position
        List<GeneralRegion> regions = Utils.getRegionsInSelection(new CuboidSelection(block.getWorld(), block.getLocation(), block.getLocation()));
        if (regions.isEmpty()) {
            plugin.message(sender, "addsign-noRegions");
            return;
        } else if (regions.size() > 1) {
            plugin.message(sender, "addsign-couldNotDetect", regions.get(0).getName(), regions.get(1).getName());
            return;
        }
        region = regions.get(0);
    }
    Sign sign = (Sign) block.getState().getData();
    String profile = null;
    if (args.length > 2) {
        profile = args[2];
        Set<String> profiles = plugin.getConfig().getConfigurationSection("signProfiles").getKeys(false);
        if (!profiles.contains(profile)) {
            plugin.message(sender, "addsign-wrongProfile", Utils.createCommaSeparatedList(profiles), region);
            return;
        }
    }
    RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
    if (regionSign != null) {
        plugin.message(sender, "addsign-alreadyRegistered", regionSign.getRegion());
        return;
    }
    region.getSignsFeature().addSign(block.getLocation(), block.getType(), sign.getFacing(), profile);
    if (profile == null) {
        plugin.message(sender, "addsign-success", region);
    } else {
        plugin.message(sender, "addsign-successProfile", profile, region);
    }
    region.update();
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) CuboidSelection(com.sk89q.worldedit.bukkit.selections.CuboidSelection) GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion) Block(org.bukkit.block.Block) Sign(org.bukkit.material.Sign) RegionSign(me.wiefferink.areashop.features.signs.RegionSign) RegionSign(me.wiefferink.areashop.features.signs.RegionSign)

Example 2 with Sign

use of org.bukkit.material.Sign in project Glowstone by GlowstoneMC.

the class BlockHopper method pullItems.

private void pullItems(GlowBlock block, HopperEntity hopper) {
    GlowBlock source = block.getRelative(BlockFace.UP);
    MaterialData data = source.getState().getData();
    if (!source.getType().isSolid() || (data instanceof Step && !((Step) data).isInverted()) || (data instanceof WoodenStep && !((WoodenStep) data).isInverted()) || (data instanceof Sign) || (data instanceof Rails)) {
        GlowItem item = getFirstDroppedItem(source.getLocation());
        if (item == null) {
            return;
        }
        ItemStack stack = item.getItemStack();
        HashMap<Integer, ItemStack> add = hopper.getInventory().addItem(stack);
        if (add.size() > 0) {
            item.setItemStack(add.get(0));
        } else {
            item.remove();
        }
    } else if (source.getBlockEntity() != null && source.getBlockEntity() instanceof ContainerEntity) {
        ContainerEntity sourceContainer = (ContainerEntity) source.getBlockEntity();
        if (sourceContainer.getInventory() == null || sourceContainer.getInventory().getContents().length == 0) {
            return;
        }
        ItemStack item = getFirstItem(sourceContainer);
        if (item == null) {
            return;
        }
        ItemStack clone = item.clone();
        clone.setAmount(1);
        if (hopper.getInventory().addItem(clone).size() > 0) {
            return;
        }
        if (item.getAmount() - 1 == 0) {
            sourceContainer.getInventory().remove(item);
        } else {
            item.setAmount(item.getAmount() - 1);
        }
    }
}
Also used : WoodenStep(org.bukkit.material.WoodenStep) Rails(org.bukkit.material.Rails) GlowBlock(net.glowstone.block.GlowBlock) ContainerEntity(net.glowstone.block.entity.ContainerEntity) Sign(org.bukkit.material.Sign) MaterialData(org.bukkit.material.MaterialData) WoodenStep(org.bukkit.material.WoodenStep) Step(org.bukkit.material.Step) ItemStack(org.bukkit.inventory.ItemStack) GlowItem(net.glowstone.entity.objects.GlowItem)

Example 3 with Sign

use of org.bukkit.material.Sign in project Glowstone by GlowstoneMC.

the class BlockSign method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    state.setType(getMaterial());
    if (!(state.getData() instanceof Sign)) {
        warnMaterialData(Sign.class, state.getData());
        return;
    }
    Sign sign = (Sign) state.getData();
    sign.setFacingDirection(sign.isWallSign() ? face : player.getFacing().getOppositeFace());
}
Also used : Sign(org.bukkit.material.Sign)

Example 4 with Sign

use of org.bukkit.material.Sign in project AreaShop by NLthijs48.

the class SignLinkerManager method onPlayerInteract.

/**
 * On player interactions.
 * @param event The PlayerInteractEvent
 */
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
    if (isInSignLinkMode(event.getPlayer())) {
        event.setCancelled(true);
        Player player = event.getPlayer();
        SignLinker linker = signLinkers.get(event.getPlayer().getUniqueId());
        if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            // Get the region
            BlockIterator blockIterator = new BlockIterator(player, 100);
            while (blockIterator.hasNext()) {
                Block next = blockIterator.next();
                List<GeneralRegion> regions = Utils.getRegions(next.getLocation());
                if (regions.size() == 1) {
                    linker.setRegion(regions.get(0));
                    return;
                } else if (regions.size() > 1) {
                    Set<String> names = new HashSet<>();
                    for (GeneralRegion region : regions) {
                        names.add(region.getName());
                    }
                    plugin.message(player, "linksigns-multipleRegions", Utils.createCommaSeparatedList(names));
                    plugin.message(player, "linksigns-multipleRegionsAdvice");
                    return;
                }
            }
            // No regions found within the maximum range
            plugin.message(player, "linksigns-noRegions");
        } else if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
            Block block = null;
            BlockIterator blockIterator = new BlockIterator(player, 100);
            while (blockIterator.hasNext() && block == null) {
                Block next = blockIterator.next();
                if (next.getType() != Material.AIR) {
                    block = next;
                }
            }
            if (block == null || !(block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST)) {
                plugin.message(player, "linksigns-noSign");
                return;
            }
            RegionSign regionSign = SignsFeature.getSignByLocation(block.getLocation());
            if (regionSign != null) {
                plugin.message(player, "linksigns-alreadyRegistered", regionSign.getRegion());
                return;
            }
            Sign sign = (Sign) block.getState().getData();
            linker.setSign(block.getLocation(), block.getType(), sign.getFacing());
        }
    }
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) Player(org.bukkit.entity.Player) HashSet(java.util.HashSet) Set(java.util.Set) GeneralRegion(me.wiefferink.areashop.regions.GeneralRegion) Block(org.bukkit.block.Block) Sign(org.bukkit.material.Sign) RegionSign(me.wiefferink.areashop.features.signs.RegionSign) RegionSign(me.wiefferink.areashop.features.signs.RegionSign) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Sign (org.bukkit.material.Sign)4 RegionSign (me.wiefferink.areashop.features.signs.RegionSign)2 GeneralRegion (me.wiefferink.areashop.regions.GeneralRegion)2 Block (org.bukkit.block.Block)2 Player (org.bukkit.entity.Player)2 BlockIterator (org.bukkit.util.BlockIterator)2 CuboidSelection (com.sk89q.worldedit.bukkit.selections.CuboidSelection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 GlowBlock (net.glowstone.block.GlowBlock)1 ContainerEntity (net.glowstone.block.entity.ContainerEntity)1 GlowItem (net.glowstone.entity.objects.GlowItem)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1 MaterialData (org.bukkit.material.MaterialData)1 Rails (org.bukkit.material.Rails)1 Step (org.bukkit.material.Step)1 WoodenStep (org.bukkit.material.WoodenStep)1