Search in sources :

Example 1 with TileEntity

use of org.spongepowered.api.block.tileentity.TileEntity in project Skree by Skelril.

the class GoldRushListener method onPlayerInteractEvent.

@Listener(order = Order.FIRST)
public void onPlayerInteractEvent(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
    Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent())
        return;
    GoldRushInstance inst = optInst.get();
    BlockSnapshot snapshot = event.getTargetBlock();
    BlockState state = snapshot.getState();
    if (!snapshot.getLocation().isPresent()) {
        return;
    }
    Location<World> targetBlock = snapshot.getLocation().get();
    if (state.getType() == BlockTypes.WALL_SIGN && inst.getLockLocations().contains(targetBlock)) {
        Optional<TileEntity> optTileEnt = snapshot.getLocation().get().getTileEntity();
        if (!optTileEnt.isPresent()) {
            return;
        }
        TileEntity tileEntity = optTileEnt.get();
        Optional<List<Text>> optTexts = tileEntity.get(Keys.SIGN_LINES);
        if (!optTexts.isPresent()) {
            return;
        }
        List<Text> texts = optTexts.get();
        boolean unlocked = false;
        String text = texts.get(1).toPlain().toLowerCase();
        net.minecraft.item.ItemStack[] itemStacks = tf(player).inventory.mainInventory;
        for (int i = 0; i < itemStacks.length; ++i) {
            ItemStack is = itemStacks[i];
            if (is == null || is.getItem() != CustomItemTypes.GOLD_RUSH_KEY) {
                continue;
            }
            if (text.contains("blue")) {
                if (is.getItemDamage() != 1) {
                    continue;
                }
            } else if (text.contains("red")) {
                if (is.getItemDamage() != 0) {
                    continue;
                }
            } else {
                continue;
            }
            unlocked = true;
            itemStacks[i] = null;
            break;
        }
        if (unlocked) {
            tf(player).inventoryContainer.detectAndSendChanges();
            texts.set(2, Text.of("Locked"));
            texts.set(3, Text.of("- Unlocked -"));
            tileEntity.offer(Keys.SIGN_LINES, texts);
        }
    } else if (state.getType() == BlockTypes.LEVER) {
        Task.builder().execute(() -> {
            if (inst.checkLevers())
                inst.completeGame();
        }).delayTicks(1).submit(SkreePlugin.inst());
    } else if (targetBlock.equals(inst.getRewardChestLoc()) && inst.isComplete()) {
        event.setUseItemResult(Tristate.FALSE);
        event.setUseBlockResult(Tristate.FALSE);
        player.sendMessage(Text.of(TextColors.YELLOW, "You have successfully robbed the bank!"));
        inst.payPlayer(player);
    } else if (!inst.isLocked()) {
        if (state.getType() == BlockTypes.STONE_BUTTON) {
            inst.tryToStart();
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) BlockState(org.spongepowered.api.block.BlockState) ItemStack(net.minecraft.item.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 2 with TileEntity

use of org.spongepowered.api.block.tileentity.TileEntity in project Skree by Skelril.

the class GoldRushInstance method populateChest.

private void populateChest() {
    for (Location<World> chest : chestBlocks) {
        // TODO Sponge port
        Optional<TileEntity> optTileEnt = chest.getTileEntity();
        if (optTileEnt.isPresent() && optTileEnt.get() instanceof IInventory) {
            IInventory inventory = ((IInventory) optTileEnt.get());
            int iterationTimes = Probability.getRandom(27);
            for (int i = iterationTimes; i > 0; --i) {
                ItemStack targetStack;
                int goldRand = Probability.getRandom(Probability.getRandom(Probability.getRandom(64)));
                if (Probability.getChance(1000)) {
                    targetStack = makePrizeBox(newItemStack(BlockTypes.GOLD_BLOCK, goldRand));
                } else {
                    targetStack = makePrizeBox(newItemStack(ItemTypes.GOLD_INGOT, goldRand));
                }
                inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, tf(targetStack));
            }
            if (Probability.getChance(10000 / iterationTimes)) {
                inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, tf(makePrizeBox(newItemStack(CustomItemTypes.PHANTOM_HYMN))));
            }
        }
    }
    for (int i = 0; i < 2; i++) {
        Optional<TileEntity> optTileEnt = Probability.pickOneOf(chestBlocks).getTileEntity();
        if (optTileEnt.isPresent() && optTileEnt.get() instanceof IInventory) {
            IInventory inventory = ((IInventory) optTileEnt.get());
            inventory.setInventorySlotContents(Probability.getRandom(inventory.getSizeInventory()) - 1, new net.minecraft.item.ItemStack(CustomItemTypes.GOLD_RUSH_KEY, 1, i));
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) World(org.spongepowered.api.world.World) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 3 with TileEntity

use of org.spongepowered.api.block.tileentity.TileEntity in project TotalEconomy by Erigitic.

the class TEJobManager method onSignInteract.

/**
     * Called when a player clicks a sign. If the clicked sign is a "Job Changing" sign then the player's job will
     * be changed on click.
     *
     * @param event InteractBlockEvent
     */
@Listener
public void onSignInteract(InteractBlockEvent event) {
    if (event.getCause().first(Player.class).isPresent()) {
        Player player = event.getCause().first(Player.class).get();
        if (event.getTargetBlock().getLocation().isPresent()) {
            Optional<TileEntity> tileEntityOpt = event.getTargetBlock().getLocation().get().getTileEntity();
            if (tileEntityOpt.isPresent()) {
                TileEntity tileEntity = tileEntityOpt.get();
                if (tileEntity instanceof Sign) {
                    Sign sign = (Sign) tileEntity;
                    Optional<SignData> data = sign.getOrCreate(SignData.class);
                    if (data.isPresent()) {
                        SignData signData = data.get();
                        Text lineOneText = signData.lines().get(0);
                        Text lineTwoText = signData.lines().get(1);
                        String lineOne = lineOneText.toPlain();
                        String lineTwo = lineTwoText.toPlain().toLowerCase();
                        if (lineOne.equals("[TEJobs]")) {
                            if (jobExists(lineTwo)) {
                                if (setJob(player, lineTwo)) {
                                    player.sendMessage(Text.of(TextColors.GRAY, "Job changed to: ", TextColors.GOLD, lineTwo));
                                } else {
                                    player.sendMessage(Text.of(TextColors.RED, "[TE] Failed to set job. Contact your administrator."));
                                }
                            } else {
                                player.sendMessage(Text.of(TextColors.RED, "[TE] Sorry, this job does not exist"));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Player(org.spongepowered.api.entity.living.player.Player) SignData(org.spongepowered.api.data.manipulator.mutable.tileentity.SignData) Sign(org.spongepowered.api.block.tileentity.Sign) Text(org.spongepowered.api.text.Text) Listener(org.spongepowered.api.event.Listener)

Example 4 with TileEntity

use of org.spongepowered.api.block.tileentity.TileEntity in project ClearMob by axle2005.

the class CommandDump method tileEntityDump.

private void tileEntityDump() {
    List<String> listdump = new ArrayList<String>();
    List<Integer> count = new ArrayList<Integer>();
    for (World world : Sponge.getServer().getWorlds()) {
        for (TileEntity entity : world.getTileEntities()) {
            if (!listdump.contains("Tile Entity: " + entity.getType()) && !plugin.getListEntityType().contains(entity.getType())) {
                listdump.add("Tile Entity: " + entity.getType());
                count.add(1);
            } else if (listdump.contains("Tile Entity: " + entity.getType())) {
                count.set(listdump.indexOf("Tile Entity: " + entity.getType()), count.get(listdump.indexOf("Tile Entity: " + entity.getType())) + 1);
            }
        }
    }
    if (listdump.isEmpty()) {
        plugin.getLogger().info("No Tile Entities to Add");
    } else {
        for (String s : listdump) {
            plugin.getLogger().info(s);
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World)

Example 5 with TileEntity

use of org.spongepowered.api.block.tileentity.TileEntity in project ClearMob by axle2005.

the class CommandDump method entityAllDump.

private void entityAllDump() {
    List<String> listentitydump = new ArrayList<String>();
    List<String> listtiledump = new ArrayList<String>();
    List<Integer> listentitycount = new ArrayList<Integer>();
    List<Integer> listtilecount = new ArrayList<Integer>();
    for (World world : Sponge.getServer().getWorlds()) {
        for (Entity entity : world.getEntities()) {
            if (!listentitydump.contains("Entity: " + entity.getType().getId())) {
                listentitydump.add("Entity: " + entity.getType().getId());
                listentitycount.add(1);
            } else if (listentitydump.contains("Entity: " + entity.getType().getId())) {
                listentitycount.set(listentitydump.indexOf("Entity: " + entity.getType().getId()), listentitycount.get(listentitydump.indexOf("Entity: " + entity.getType().getId())) + 1);
            }
        }
        for (TileEntity entity : world.getTileEntities()) {
            if (!listtiledump.contains("Tile Entity: " + entity.getType().getId())) {
                listtiledump.add("Tile Entity: " + entity.getType().getId());
                listtilecount.add(1);
            } else if (listtiledump.contains("Tile Entity: " + entity.getType().getId())) {
                listtilecount.set(listtiledump.indexOf("Tile Entity: " + entity.getType().getId()), listtilecount.get(listtiledump.indexOf("Tile Entity: " + entity.getType().getId())) + 1);
            }
        }
    }
    if (listentitydump.isEmpty()) {
        plugin.getLogger().info("No Entities to Add");
    } else {
        for (int i = 0; i <= listentitydump.size() - 1; i++) {
            plugin.getLogger().info(listentitydump.get(i) + ": (" + listentitycount.get(i) + ")");
        }
    }
    if (listtiledump.isEmpty()) {
        plugin.getLogger().info("No Tile Entities to Add");
    } else {
        for (int i = 0; i <= listtiledump.size() - 1; i++) {
            plugin.getLogger().info(listtiledump.get(i) + ": (" + listtilecount.get(i) + ")");
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Entity(org.spongepowered.api.entity.Entity) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World)

Aggregations

TileEntity (org.spongepowered.api.block.tileentity.TileEntity)8 World (org.spongepowered.api.world.World)6 ArrayList (java.util.ArrayList)4 IInventory (net.minecraft.inventory.IInventory)2 BlockState (org.spongepowered.api.block.BlockState)2 Listener (org.spongepowered.api.event.Listener)2 Text (org.spongepowered.api.text.Text)2 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)1 ItemStack (net.minecraft.item.ItemStack)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 Sign (org.spongepowered.api.block.tileentity.Sign)1 SignData (org.spongepowered.api.data.manipulator.mutable.tileentity.SignData)1 Entity (org.spongepowered.api.entity.Entity)1 Player (org.spongepowered.api.entity.living.player.Player)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Location (org.spongepowered.api.world.Location)1