Search in sources :

Example 46 with BlockType

use of org.spongepowered.api.block.BlockType in project modules-extra by CubeEngine.

the class MarketSignListener method onSignPlace.

@Listener(order = Order.POST)
public void onSignPlace(ChangeBlockEvent.Place event, @First Player player) {
    if (event.getTransactions().size() > 1 || !module.getEditModeCommand().hasUser(player)) {
        return;
    }
    for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
        BlockType type = trans.getFinal().getState().getType();
        if (// placed sign
        type == BlockTypes.STANDING_SIGN || type == BlockTypes.WALL_SIGN) {
            if (!player.hasPermission(module.perms().EDIT_USE.getId())) {
                event.setCancelled(true);
                i18n.send(player, NEGATIVE, "You are not allowed to create market signs!");
                return;
            }
            MarketSignData data = new MarketSignData();
            data.setID(UUID.randomUUID());
            data.setOwner(player.getUniqueId());
            Location<World> loc = trans.getFinal().getLocation().get();
            loc.offer(data);
            manager.setSign(loc, player);
            Sponge.getCauseStackManager().pushCause(player);
            player.closeInventory();
        }
    }
}
Also used : BlockType(org.spongepowered.api.block.BlockType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) MarketSignData(org.cubeengine.module.signmarket.data.MarketSignData) ImmutableMarketSignData(org.cubeengine.module.signmarket.data.ImmutableMarketSignData) World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Example 47 with BlockType

use of org.spongepowered.api.block.BlockType in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method placeBlock.

@Listener(order = Order.PRE)
public void placeBlock(ChangeBlockEvent event) {
    if (forceStop) {
        return;
    }
    if (event.getCause().root() instanceof Player) {
        Player plr = (Player) event.getCause().root();
        if (event instanceof ChangeBlockEvent.Place || event instanceof ChangeBlockEvent.Break) {
            BlockType t = event.getTransactions().get(0).getOriginal().getLocation().get().getBlock().getType();
            Location<World> location = event.getTransactions().get(0).getOriginal().getLocation().get();
            // System.out.println(event instanceof ChangeBlockEvent.Break);
            if (validCrateBlocks.contains(t)) {
                if (event instanceof ChangeBlockEvent.Place) {
                    if (plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
                        Optional<Object> tt = plr.getItemInHand(HandTypes.MAIN_HAND).get().toContainer().get(DataQuery.of("UnsafeData", "crateID"));
                        if (tt.isPresent()) {
                            String crateID = tt.get().toString();
                            if (!plr.hasPermission("huskycrates.tester")) {
                                event.setCancelled(true);
                                return;
                            }
                            if (!crateUtilities.physicalCrates.containsKey(location))
                                crateUtilities.physicalCrates.put(location, new PhysicalCrate(location, crateID, this, false));
                            crateUtilities.physicalCrates.get(location).createHologram();
                            try {
                                DBReader.saveHuskyData();
                            } catch (SQLException e) {
                                e.printStackTrace();
                            }
                            return;
                        }
                    }
                }
            } else if (event instanceof ChangeBlockEvent.Break) {
                if (crateUtilities.physicalCrates.containsKey(location)) {
                    if (!plr.hasPermission("huskycrates.tester")) {
                        event.setCancelled(true);
                        return;
                    }
                    if (!crateUtilities.physicalCrates.get(location).isEntity)
                        crateUtilities.physicalCrates.get(location).ent.remove();
                    crateUtilities.physicalCrates.remove(location);
                    crateUtilities.brokenCrates.add(location);
                    try {
                        DBReader.saveHuskyData();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) SQLException(java.sql.SQLException) PhysicalCrate(com.codehusky.huskycrates.crate.PhysicalCrate) World(org.spongepowered.api.world.World) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) BlockType(org.spongepowered.api.block.BlockType) JSONObject(org.json.JSONObject) Listener(org.spongepowered.api.event.Listener)

Example 48 with BlockType

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

the class TheForgeInstance method runOreCheck.

private void runOreCheck() {
    for (Item item : getContained(Item.class)) {
        BlockType belowType = item.getLocation().add(0, -1, 0).getBlockType();
        if (belowType == BlockTypes.GOLD_BLOCK) {
            addResource(item.item().get());
            item.remove();
        }
    }
    state.save();
}
Also used : Item(org.spongepowered.api.entity.Item) BlockType(org.spongepowered.api.block.BlockType)

Example 49 with BlockType

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

the class TheForgeListener method isFlying.

// Poor man's flight check
private boolean isFlying(Player player) {
    BlockType blockBelow = player.getLocation().add(0, -1, 0).getBlockType();
    BlockType blockBelowBelow = player.getLocation().add(0, -2, 0).getBlockType();
    return blockBelow == BlockTypes.AIR && blockBelowBelow == BlockTypes.AIR;
}
Also used : BlockType(org.spongepowered.api.block.BlockType)

Example 50 with BlockType

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

the class MagicWand method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    boolean survival = player.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) == GameModes.SURVIVAL;
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    if (optHeldItem.get().getItem() != this) {
        return;
    }
    event.setUseBlockResult(Tristate.FALSE);
    Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
    if (!optLoc.isPresent()) {
        return;
    }
    Location<World> loc = optLoc.get();
    BlockType targetType = loc.getBlockType();
    if (targetType == CustomBlockTypes.MAGIC_LADDER) {
        MagicBlockStateHelper.startLadder(loc);
    } else if (targetType == CustomBlockTypes.MAGIC_PLATFORM) {
        MagicBlockStateHelper.startPlatform(loc);
    } else {
        return;
    }
    if (!survival) {
        MagicBlockStateHelper.resetCounts();
        return;
    }
    MagicBlockStateHelper.dropItems(loc, event.getCause());
}
Also used : BlockType(org.spongepowered.api.block.BlockType) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Aggregations

BlockType (org.spongepowered.api.block.BlockType)80 World (org.spongepowered.api.world.World)34 Listener (org.spongepowered.api.event.Listener)21 BlockState (org.spongepowered.api.block.BlockState)18 Location (org.spongepowered.api.world.Location)17 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)16 ItemStack (org.spongepowered.api.item.inventory.ItemStack)14 Vector3i (com.flowpowered.math.vector.Vector3i)12 Player (org.spongepowered.api.entity.living.player.Player)12 Optional (java.util.Optional)11 Direction (org.spongepowered.api.util.Direction)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 Keys (org.spongepowered.api.data.key.Keys)9 ArrayList (java.util.ArrayList)8 List (java.util.List)7 Set (java.util.Set)7 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)7 Text (org.spongepowered.api.text.Text)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6