Search in sources :

Example 6 with WallSign

use of org.bukkit.block.data.type.WallSign in project Movecraft by APDevTeam.

the class CruiseSign method onSignClick.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onSignClick(@NotNull PlayerInteractEvent event) {
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
        return;
    }
    BlockState state = event.getClickedBlock().getState();
    if (!(state instanceof Sign)) {
        return;
    }
    Sign sign = (Sign) state;
    if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Cruise: OFF")) {
        if (CraftManager.getInstance().getCraftByPlayer(event.getPlayer()) == null) {
            return;
        }
        Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
        if (!c.getType().getBoolProperty(CraftType.CAN_CRUISE)) {
            return;
        }
        // c.resetSigns(false, true, true);
        sign.setLine(0, "Cruise: ON");
        sign.update(true);
        if (sign.getBlockData() instanceof WallSign) {
            c.setCruiseDirection(CruiseDirection.fromBlockFace(((WallSign) sign.getBlockData()).getFacing()));
        } else {
            c.setCruiseDirection(CruiseDirection.NONE);
        }
        c.setLastCruiseUpdate(System.currentTimeMillis());
        c.setCruising(true);
        c.resetSigns(sign);
        if (!c.getType().getBoolProperty(CraftType.MOVE_ENTITIES)) {
            CraftManager.getInstance().addReleaseTask(c);
        }
        return;
    }
    if (ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase("Cruise: ON") && CraftManager.getInstance().getCraftByPlayer(event.getPlayer()) != null && CraftManager.getInstance().getCraftByPlayer(event.getPlayer()).getType().getBoolProperty(CraftType.CAN_CRUISE)) {
        Craft c = CraftManager.getInstance().getCraftByPlayer(event.getPlayer());
        sign.setLine(0, "Cruise: OFF");
        sign.update(true);
        c.setCruising(false);
        c.resetSigns(sign);
    }
}
Also used : WallSign(org.bukkit.block.data.type.WallSign) BlockState(org.bukkit.block.BlockState) Craft(net.countercraft.movecraft.craft.Craft) Sign(org.bukkit.block.Sign) WallSign(org.bukkit.block.data.type.WallSign) EventHandler(org.bukkit.event.EventHandler)

Example 7 with WallSign

use of org.bukkit.block.data.type.WallSign in project ParamaLegends by aaqil-a.

the class PlayerShopListener method onInteract.

// interacting with shop
@EventHandler
public void onInteract(PlayerInteractEvent event) {
    if (Objects.equals(event.getHand(), EquipmentSlot.OFF_HAND))
        return;
    if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        if (event.getClickedBlock() != null) {
            Block block = event.getClickedBlock();
            Player player = event.getPlayer();
            // lock shops
            if (block.getState() instanceof Chest) {
                Chest chest = (Chest) block.getState();
                String uuid = chest.getPersistentDataContainer().get(key, PersistentDataType.STRING);
                if (uuid != null) {
                    if (!player.getUniqueId().toString().equals(uuid)) {
                        player.sendMessage(ChatColor.RED + "You are not the owner of this shop.");
                        event.setCancelled(true);
                    }
                }
            }
            // shop interaction
            if (block.getBlockData() instanceof WallSign && block.getState() instanceof Sign) {
                Sign sign = (Sign) block.getState();
                // setting item
                if (block.hasMetadata("SHOPNOITEMPARAMA")) {
                    WallSign wallSign = (WallSign) block.getBlockData();
                    Block attached = block.getRelative(wallSign.getFacing().getOppositeFace());
                    if (attached.getType().equals(Material.CHEST)) {
                        if (player.getEquipment() != null) {
                            Chest chest = (Chest) attached.getState();
                            ItemStack item = player.getEquipment().getItemInMainHand();
                            chest.getPersistentDataContainer().set(key, PersistentDataType.STRING, player.getUniqueId().toString());
                            chest.update();
                            sign.getPersistentDataContainer().set(key, PersistentDataType.STRING, player.getUniqueId().toString());
                            sign.setLine(0, ChatColor.BOLD + player.getName());
                            sign.setLine(1, ChatColor.GOLD + sign.getLine(1));
                            sign.setLine(2, item.getType().toString());
                            sign.update();
                            block.removeMetadata("SHOPNOITEMPARAMA", plugin);
                        }
                    }
                }
                // buying items
                if (sign.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
                    String uuid = sign.getPersistentDataContainer().get(key, PersistentDataType.STRING);
                    if (uuid != null) {
                        if (player.getUniqueId().toString().equals(uuid))
                            return;
                        int price;
                        int amount;
                        try {
                            price = Integer.parseInt(sign.getLine(1).substring(2, sign.getLine(1).indexOf(" ")));
                            amount = Integer.parseInt(sign.getLine(3));
                        } catch (Exception e) {
                            return;
                        }
                        // check if player has enough lectrum
                        int lectrum = plugin.getPlayerParama(player).getLectrum();
                        if (lectrum < price) {
                            player.sendMessage(ChatColor.RED + "Insufficient lectrum.");
                            return;
                        }
                        WallSign wallSign = (WallSign) block.getBlockData();
                        Block attached = block.getRelative(wallSign.getFacing().getOppositeFace());
                        if (attached.getType().equals(Material.CHEST)) {
                            Chest chest = (Chest) attached.getState();
                            Material material = Objects.requireNonNull(Material.getMaterial(sign.getLine(2)));
                            Inventory shop = chest.getInventory();
                            if (shop.contains(material, amount)) {
                                for (ItemStack item : shop.getContents()) {
                                    if (item == null)
                                        continue;
                                    if (item.getType().equals(material)) {
                                        if (item.getAmount() >= amount) {
                                            int remaining = item.getAmount() - amount;
                                            item.setAmount(amount);
                                            player.getInventory().addItem(item);
                                            item.setAmount(remaining);
                                            amount = 0;
                                        } else {
                                            player.getInventory().addItem(item);
                                            amount -= item.getAmount();
                                            item.setAmount(0);
                                        }
                                        if (amount <= 0)
                                            break;
                                    }
                                }
                                plugin.getPlayerParama(player).removeLectrum(price);
                                int tax = 0;
                                // check tax
                                String mayorUuidString = data.getConfig().getString("mayoruuid");
                                if (mayorUuidString != null && !mayorUuidString.isBlank()) {
                                    tax = (int) Math.ceil(price / 20d);
                                    Player mayor = plugin.getServer().getPlayer(UUID.fromString(mayorUuidString));
                                    if (mayor != null) {
                                        plugin.getPlayerParama(mayor).addLectrum(tax);
                                    } else {
                                        int lectrumMayor = data.getConfig().getInt("players." + mayorUuidString + ".lectrum");
                                        data.getConfig().set("players." + mayorUuidString + ".lectrum", lectrumMayor + tax);
                                    }
                                    plugin.leaderboard.updateNetWorth(mayorUuidString);
                                }
                                int lectrumSeller;
                                Player seller = plugin.getServer().getPlayer(UUID.fromString(uuid));
                                if (seller != null) {
                                    seller.sendMessage(ChatColor.GREEN + player.getName() + " purchased " + sign.getLine(3) + " " + sign.getLine(2) + " from you for " + price + " lectrum.");
                                    plugin.getPlayerParama(seller).addLectrum(price - tax);
                                } else {
                                    lectrumSeller = data.getConfig().getInt("players." + uuid + ".lectrum");
                                    data.getConfig().set("players." + uuid + ".lectrum", lectrumSeller + price - tax);
                                    data.saveConfig();
                                }
                                player.sendMessage(ChatColor.GREEN + "Purchased " + sign.getLine(3) + " " + sign.getLine(2) + " for " + price + " lectrum.");
                                plugin.leaderboard.updateNetWorth(uuid);
                                plugin.leaderboard.updateNetWorth(player.getUniqueId().toString());
                            } else {
                                player.sendMessage(ChatColor.RED + "Shop out of stock.");
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : WallSign(org.bukkit.block.data.type.WallSign) Chest(org.bukkit.block.Chest) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) WallSign(org.bukkit.block.data.type.WallSign) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 8 with WallSign

use of org.bukkit.block.data.type.WallSign in project ParamaLegends by aaqil-a.

the class PlayerShopListener method onChangeSign.

// Creating shop
@EventHandler
public void onChangeSign(SignChangeEvent event) {
    Block block = event.getBlock();
    if (block.getBlockData() instanceof WallSign) {
        WallSign sign = (WallSign) block.getBlockData();
        Block attached = block.getRelative(sign.getFacing().getOppositeFace());
        // check if sign is placed on chest
        if (attached.getType().equals(Material.CHEST)) {
            String firstLine = event.getLine(0);
            if (firstLine != null && firstLine.equals("[ParamaShop]")) {
                Player player = event.getPlayer();
                String price = event.getLine(1);
                String amount = event.getLine(3);
                if (price != null && amount != null) {
                    if (price.endsWith("Lectrum") || price.endsWith("lectrum"))
                        try {
                            Integer.parseInt(price.substring(0, price.indexOf(" ")));
                        } catch (Exception e) {
                            player.sendMessage(ChatColor.RED + "Invalid price.");
                            return;
                        }
                    else {
                        player.sendMessage(ChatColor.RED + "Invalid price.");
                        return;
                    }
                    try {
                        Integer.parseInt(amount);
                    } catch (NumberFormatException e) {
                        player.sendMessage(ChatColor.RED + "Invalid amount.");
                        return;
                    }
                    block.setMetadata("SHOPNOITEMPARAMA", new FixedMetadataValue(plugin, 1));
                    player.sendMessage(ChatColor.GREEN + "Right click sign with item.");
                }
            } else {
                // remove metadata if not player shop
                block.removeMetadata("SIGNCHESTPARAMA", plugin);
            }
        }
    }
}
Also used : WallSign(org.bukkit.block.data.type.WallSign) Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) EventHandler(org.bukkit.event.EventHandler)

Example 9 with WallSign

use of org.bukkit.block.data.type.WallSign in project SignShop by wargamer.

the class SignShopBlockListener method getAttachables.

private List<Block> getAttachables(Block originalBlock) {
    List<Block> attachables = new ArrayList<>();
    List<BlockFace> checkFaces = new ArrayList<>();
    checkFaces.add(BlockFace.UP);
    checkFaces.add(BlockFace.NORTH);
    checkFaces.add(BlockFace.EAST);
    checkFaces.add(BlockFace.SOUTH);
    checkFaces.add(BlockFace.WEST);
    Block relativeBlock;
    BlockData relativeBlockData;
    for (BlockFace face : checkFaces) {
        relativeBlock = originalBlock.getRelative(face);
        relativeBlockData = relativeBlock.getBlockData();
        if (relativeBlockData instanceof Switch) {
            Switch switchData = (Switch) relativeBlockData;
            if (switchData.getFace() == Switch.Face.FLOOR && relativeBlock.getRelative(BlockFace.DOWN).equals(originalBlock)) {
                attachables.add(relativeBlock);
            }
        } else if (relativeBlockData instanceof WallSign) {
            WallSign wallSign = (WallSign) relativeBlockData;
            if (relativeBlock.getRelative(wallSign.getFacing().getOppositeFace()).equals(originalBlock)) {
                // may need to add getOppositeFace
                attachables.add(relativeBlock);
            }
        } else if (relativeBlockData instanceof Sign)
            if (relativeBlock.getRelative(BlockFace.DOWN).equals(originalBlock)) {
                attachables.add(relativeBlock);
            }
    }
    return attachables;
}
Also used : WallSign(org.bukkit.block.data.type.WallSign) Switch(org.bukkit.block.data.type.Switch) BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) WallSign(org.bukkit.block.data.type.WallSign) Sign(org.bukkit.block.data.type.Sign) BlockData(org.bukkit.block.data.BlockData)

Example 10 with WallSign

use of org.bukkit.block.data.type.WallSign in project Towny by TownyAdvanced.

the class TownyPlayerListener method onAdminToolUseOnBlocks.

/*
	 *  Handles AdminTool use on Blocks
	 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onAdminToolUseOnBlocks(PlayerInteractEvent event) {
    if (plugin.isError()) {
        event.setCancelled(true);
        return;
    }
    if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld()))
        return;
    if (event.hasItem() && event.getPlayer().getInventory().getItemInMainHand().getType() == Material.getMaterial(TownySettings.getTool()) && TownyUniverse.getInstance().getPermissionSource().isTownyAdmin(event.getPlayer()) && event.getClickedBlock() != null) {
        Player player = event.getPlayer();
        Block block = event.getClickedBlock();
        if (Tag.SIGNS.isTagged(block.getType())) {
            BlockFace facing = null;
            if (block.getBlockData() instanceof Sign) {
                org.bukkit.block.data.type.Sign sign = (org.bukkit.block.data.type.Sign) block.getBlockData();
                facing = sign.getRotation();
            }
            if (block.getBlockData() instanceof WallSign) {
                org.bukkit.block.data.type.WallSign sign = (org.bukkit.block.data.type.WallSign) block.getBlockData();
                facing = sign.getFacing();
            }
            TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Sign Info"), ChatTools.formatCommand("", "Sign Type", "", block.getType().name()), ChatTools.formatCommand("", "Facing", "", facing.toString())));
        } else if (Tag.DOORS.isTagged(block.getType())) {
            org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData();
            TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Door Info"), ChatTools.formatCommand("", "Door Type", "", block.getType().name()), ChatTools.formatCommand("", "hinged on ", "", String.valueOf(door.getHinge())), ChatTools.formatCommand("", "isOpen", "", String.valueOf(door.isOpen())), ChatTools.formatCommand("", "getFacing", "", door.getFacing().name())));
        } else {
            TownyMessaging.sendMessage(player, Arrays.asList(ChatTools.formatTitle("Block Info"), ChatTools.formatCommand("", "Material", "", block.getType().name()), ChatTools.formatCommand("", "MaterialData", "", block.getBlockData().getAsString())));
        }
        event.setUseInteractedBlock(Event.Result.DENY);
        event.setCancelled(true);
    }
}
Also used : WallSign(org.bukkit.block.data.type.WallSign) Player(org.bukkit.entity.Player) BlockFace(org.bukkit.block.BlockFace) WallSign(org.bukkit.block.data.type.WallSign) Sign(org.bukkit.block.data.type.Sign) Block(org.bukkit.block.Block) TownBlock(com.palmergames.bukkit.towny.object.TownBlock) WallSign(org.bukkit.block.data.type.WallSign) Sign(org.bukkit.block.data.type.Sign) EventHandler(org.bukkit.event.EventHandler)

Aggregations

WallSign (org.bukkit.block.data.type.WallSign)22 Block (org.bukkit.block.Block)11 EventHandler (org.bukkit.event.EventHandler)11 BlockData (org.bukkit.block.data.BlockData)10 Player (org.bukkit.entity.Player)9 Sign (org.bukkit.block.Sign)7 BlockState (org.bukkit.block.BlockState)6 Sign (org.bukkit.block.data.type.Sign)5 Location (org.bukkit.Location)4 BlockFace (org.bukkit.block.BlockFace)3 ArrayList (java.util.ArrayList)2 Craft (net.countercraft.movecraft.craft.Craft)2 Material (org.bukkit.Material)2 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)1 Structure (eelfloat.replcraft.Structure)1 InvalidStructure (eelfloat.replcraft.exceptions.InvalidStructure)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Knocker (me.gameisntover.kbffa.api.Knocker)1 DataBlock (me.gameisntover.kbffa.arena.regions.DataBlock)1