Package org.bukkit.block

Examples of org.bukkit.block.Block


    if (!War.war.isLoaded()) {
      return;
    }

    Player player = event.getPlayer();
    Block block = event.getBlock();
    if (player == null || block == null) {
      return;
    }

    Team team = Team.getTeamByPlayerName(player.getName());
    Warzone zone = Warzone.getZoneByLocation(player);
    // Monument capturing
    if (team != null && block != null && zone != null
        && zone.isMonumentCenterBlock(block)
        && team.getKind().isTeamBlock(block.getState())) {
      Monument monument = zone.getMonumentFromCenterBlock(block);
      if (monument != null && !monument.hasOwner()) {
        monument.capture(team);
        if (War.war.isSpoutServer()) {
          for (Player p : team.getPlayers()) {
            SpoutPlayer sp = SpoutManager.getPlayer(p);
            if (sp.isSpoutCraftEnabled()) {
                      sp.sendNotification(
                          SpoutDisplayer.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()),
                          SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "capped by " + team.getKind().getColor() + player.getName() + ChatColor.YELLOW + "!"),
                          team.getKind().getMaterial(),
                          team.getKind().getData(),
                          10000);
            }
          }
        }
        zone.broadcast("zone.monument.capture", monument.getName(), team.getName());
        event.setCancelled(false);
        return; // important otherwise cancelled down a few line by isImportantblock
      } else {
        War.war.badMsg(player, "zone.monument.badblock");
        cancelAndKeepItem(event);
        return;
      }
    }

    boolean isZoneMaker = War.war.isZoneMaker(player);
    // prevent build in important parts
    if (zone != null
        && (zone.isImportantBlock(block) || zone.isOpponentSpawnPeripheryBlock(team, block))
        && (!isZoneMaker || (isZoneMaker && team != null))) {
      War.war.badMsg(player, "build.denied.location");
      cancelAndKeepItem(event);
      return;
    }

    // protect warzone lobbies
    for (Warzone wz : War.war.getWarzones()) {
      if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
        War.war.badMsg(player, "build.denied.location");
        cancelAndKeepItem(event);
        return;
      }
    }

    // protect the hub
    if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
      War.war.badMsg(player, "build.denied.location");
      cancelAndKeepItem(event);
      return;
    }

    // buildInZonesOnly
    if (zone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
      if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
        War.war.badMsg(player, "build.denied.outside");
      }
      cancelAndKeepItem(event);
      return;
    }

    // can't place a block of your team's color
    if (team != null && block.getType() == team.getKind().getMaterial() && block.getState().getData() == team.getKind().getBlockData()) {
      War.war.badMsg(player, "build.denied.teamblock");
      cancelAndKeepItem(event);
      return;
    }

    // a flag thief can't drop his flag
    if (team != null && zone != null && zone.isFlagThief(player.getName())) {
      War.war.badMsg(player, "drop.flag.disabled");
      cancelAndKeepItem(event);
      return;
    }
   
    // a bomb thief can't drop his bomb
    if (team != null && zone != null && zone.isBombThief(player.getName())) {
      War.war.badMsg(player, "drop.bomb.disabled");
      cancelAndKeepItem(event);
      return;
    }
   
    // a cake thief can't drop his cake
    if (team != null && zone != null && zone.isCakeThief(player.getName())) {
      War.war.badMsg(player, "drop.cake.disabled");
      cancelAndKeepItem(event);
      return;
    }

    // unbreakableZoneBlocks
    if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)
        || (team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)))
        && (!isZoneMaker || (isZoneMaker && team != null))) {
      // if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks)
      War.war.badMsg(player, "build.denied.zone.place");
      cancelAndKeepItem(event);
      return;
    }

    if (team != null && !team.canModify(block.getType())) {
      War.war.badMsg(player, "build.denied.zone.type");
      cancelAndKeepItem(event);
      return;
    }
  }
View Full Code Here


 
  @EventHandler
  public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
    Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
    if (zone!=null) {
      Block b = event.getBlock().getRelative(event.getDirection(), 2);
      if (zone.isImportantBlock(b)) {
        event.setCancelled(true);
        return;
      }
    }
View Full Code Here

  public void onBlockBreak(final BlockBreakEvent event) {
    if (!War.war.isLoaded()) {
      return;
    }
    Player player = event.getPlayer();
    Block block = event.getBlock();
    if (player != null && block != null) {
      this.handleBreakOrDamage(player, block, event);
    }
  }
View Full Code Here

  public void onBlockDamage(final BlockDamageEvent event) {
    if (!War.war.isLoaded()) {
      return;
    }
    Player player = event.getPlayer();
    Block block = event.getBlock();
    Warzone playerZone = Warzone.getZoneByLocation(player);
    if (player != null && block != null && playerZone != null && playerZone.getWarzoneConfig().getBoolean(WarzoneConfig.INSTABREAK)) {
      Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
      if (blockZone != null && blockZone == playerZone && block.getType() != Material.BEDROCK) {
        event.setInstaBreak(true);
      }
    }
  }
View Full Code Here

      }
     
      // TODO: maybe invalidate instaBreak on some occasions.
     

        final Block block = event.getBlock();

        boolean cancelled = false;

        // Do the actual checks, if still needed. It's a good idea to make computationally cheap checks first, because
        // it may save us from doing the computationally expensive checks.
       
        final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
        final BlockBreakData data = BlockBreakData.getData(player);
        final long now = System.currentTimeMillis();
       
        final GameMode gameMode = player.getGameMode();
       
        // Has the player broken a block that was not damaged before?
        if (wrongBlock.isEnabled(player) && wrongBlock.check(player, block, cc, data, isInstaBreak)) {
          cancelled = true;
        }

        // Has the player broken more blocks per second than allowed?
        if (!cancelled && frequency.isEnabled(player) && frequency.check(player, cc, data)) {
          cancelled = true;
        }
         
        // Has the player broken blocks faster than possible?
        if (!cancelled && gameMode != GameMode.CREATIVE && fastBreak.isEnabled(player) && fastBreak.check(player, block, isInstaBreak, cc, data)) {
          cancelled = true;
        }

        // Did the arm of the player move before breaking this block?
        if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player, data)) {
          cancelled = true;
        }

        // Is the block really in reach distance?
        if (!cancelled && reach.isEnabled(player) && reach.check(player, block, data)) {
          cancelled = true;
        }

        // Did the player look at the block at all?
        if (!cancelled && direction.isEnabled(player) && direction.check(player, block, data)) {
          cancelled = true;
        }
       
        // Destroying liquid blocks.
        if (!cancelled && BlockProperties.isLiquid(block.getType()) && !player.hasPermission(Permissions.BLOCKBREAK_BREAK_LIQUID) && !NCPExemptionManager.isExempted(player, CheckType.BLOCKBREAK_BREAK)){
            cancelled = true;
        }

        // On cancel...
        if (cancelled) {
          event.setCancelled(cancelled);
          // Reset damage position:
          // TODO: Review this (!), check if set at all !?
        data.clickedX = block.getX();
        data.clickedY = block.getY();
        data.clickedZ = block.getZ();
        }
        else{
          // Invalidate last damage position:
//          data.clickedX = Integer.MAX_VALUE;
        }
View Full Code Here

public class PoweredRequirement extends AbstractRequirement{

    @Override
    public boolean check(RequirementsContext context, List<String> args) throws RequirementCheckException {
        boolean outcome = false;
        Block blockToCheck = null;


        for (String thisArg : args) {

            if (aH.matchesLocation(thisArg)) {
                blockToCheck = aH.getLocationFrom(thisArg).getBlock();
                if (blockToCheck != null)
                    dB.echoDebug(context.getScriptContainer(), "...block to check is type '" + blockToCheck.getType().toString() + "'");
            }

            else dB.echoError("Could not match argument '" + thisArg + "'");
        }

        if(blockToCheck != null) {
            if (blockToCheck.isBlockPowered()) outcome = true;
            else if (blockToCheck.isBlockIndirectlyPowered()) outcome = true;
        }

        if (outcome) dB.echoDebug(context.getScriptContainer(), "...block is powered!");
        else dB.echoDebug(context.getScriptContainer(), "...block is not powered!");
View Full Code Here

    }

    @Override
    public boolean check(RequirementsContext context, List<String> args) throws RequirementCheckException {
        boolean outcome = false;
        Block blockToCheck = null;

        if(args.size() < 1)
            throw new RequirementCheckException("Must provide a BOOKMARK:block of the block to be checked!");

        /* Get arguments */

        for (String thisArg : args) {

            if (aH.matchesLocation(thisArg)) {
                blockToCheck = aH.getLocationFrom(thisArg).getBlock();
                if (blockToCheck != null)
                    dB.echoDebug(context.getScriptContainer(), "...block to check is type '" + blockToCheck.getType().toString() + "'");
            }

            else dB.echoError("Could not match argument '" + thisArg + "'");
        }

        if (blockToCheck != null && blockToCheck.isLiquid()) outcome = true;

        if (outcome) dB.echoDebug(context.getScriptContainer(), "...block is liquid!");
        else dB.echoDebug(context.getScriptContainer(), "...block is not liquid!");

        return outcome;
View Full Code Here

    // -->
    @EventHandler
    public void blockBreak(BlockBreakEvent event) {

        Map<String, dObject> context = new HashMap<String, dObject>();
        Block block = event.getBlock();
        dMaterial material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());

        dItem item = new dItem(event.getPlayer().getItemInHand());

        // Add events
        List<String> events = new ArrayList<String>();
        events.add("player breaks block");
        events.add("player breaks " + material.identifySimple());
        events.add("player breaks block with " + item.identifySimple());
        events.add("player breaks " + material.identifySimple() +
                " with " + item.identifySimple());
        events.add("player breaks block with " + item.identifyMaterial());
        events.add("player breaks " + material.identifySimple() +
                " with " + item.identifyMaterial());

        // Look for cuboids that contain the block's location
        List<dCuboid> cuboids = dCuboid.getNotableCuboidsContaining(block.getLocation());

        if (cuboids.size() > 0) {
            events.add("player breaks block in notable cuboid");
            events.add("player breaks " + material.identifySimple() + " in notable cuboid");
            events.add("player breaks " + material.identifySimple() + " with " + item.identifySimple() + " in notable cuboid");
            events.add("player breaks " + material.identifySimple() + " with " + item.identifyMaterial() + " in notable cuboid");
        }

        dList cuboid_context = new dList();
        for (dCuboid cuboid : cuboids) {
            events.add("player breaks block in " + cuboid.identifySimple());
            events.add("player breaks " + material.identifySimple() + " in " + cuboid.identifySimple());
            events.add("player breaks " + material.identifySimple() + " with " + item.identifySimple() + " in " + cuboid.identifySimple());
            events.add("player breaks " + material.identifySimple() + " with " + item.identifyMaterial() + " in " + cuboid.identifySimple());
            cuboid_context.add(cuboid.identifySimple());
        }
        // Add in cuboids context, with either the cuboids or an empty list
        context.put("cuboids", cuboid_context);

        // Add in more context
        context.put("location", new dLocation(block.getLocation()));
        context.put("material", material);
        context.put("xp", new Element(event.getExpToDrop()));

        // Do events, get the determination
        String determination = EventManager.doEvents(events, null, new dPlayer(event.getPlayer()), context, true);

        if (determination.toUpperCase().startsWith("CANCELLED")) {
            // Straight up cancel the event
            event.setCancelled(true);

        } else if (determination.toUpperCase().startsWith("NOTHING")) {
            // Make nothing drop, usually used as "drop:nothing"
            event.setCancelled(true);
            block.setType(Material.AIR);

        } else if (Argument.valueOf(determination).matchesArgumentList(dItem.class)) {
            // Get a dList of dItems to drop
            event.setCancelled(true);
            block.setType(Material.AIR);

            // Get the list of items
            Object list = dList.valueOf(determination).filter(dItem.class);

            @SuppressWarnings("unchecked")
            List<dItem> newItems = (List<dItem>) list;

            for (dItem newItem : newItems) {
                block.getWorld().dropItemNaturally(block.getLocation(),
                        newItem.getItemStack()); // Drop each item
            }
            // TODO: Determine XP drop replacement? (Manually drop the XP like above)
        }
    }
View Full Code Here

    // -->
    @EventHandler
    public void blockPlace(BlockPlaceEvent event) {

        Map<String, dObject> context = new HashMap<String, dObject>();
        Block block = event.getBlock();
        dMaterial material = dMaterial.getMaterialFrom(block.getType(), block.getData());
        dItem item = new dItem(event.getItemInHand());
        List<String> events = new ArrayList<String>();

        // Look for cuboids that contain the block's location
        List<dCuboid> cuboids = dCuboid.getNotableCuboidsContaining(block.getLocation());

        if (cuboids.size() > 0) {
            events.add("player places block in notable cuboid");
            events.add("player places " + material.identifySimple() + " in notable cuboid");
            events.add("player places " + material.identifySimple() + " with " + item.identifySimple() + " in notable cuboid");
            events.add("player places " + material.identifySimple() + " with " + item.identifyMaterial() + " in notable cuboid");
        }

        dList cuboid_context = new dList();
        for (dCuboid cuboid : cuboids) {
            events.add("player places block in " + cuboid.identifySimple());
            events.add("player places " + material.identifySimple() + " in " + cuboid.identifySimple());
            events.add("player places " + item.identifySimple() + " in " + cuboid.identifySimple());
            cuboid_context.add(cuboid.identifySimple());
        }
        // Add in cuboids context, with either the cuboids or an empty list
        context.put("cuboids", cuboid_context);

        events.add("player places block");
        events.add("player places " + material.identifySimple());
        events.add("player places " + item.identifySimple());

        context.put("location", new dLocation(block.getLocation()));
        context.put("material", material);
        context.put("item_in_hand", item);

        String determination = EventManager.doEvents(events,
                null, new dPlayer(event.getPlayer()), context, true);
View Full Code Here

    //
    // -->
    @EventHandler
    public void signChange(final SignChangeEvent event) {

        Block block = event.getBlock();
        if (block == null || !(block.getState() instanceof Sign)) {
            return; // Fix error induced by dark magic.
        }

        List<String> events = new ArrayList<String>();
        Map<String, dObject> context = new HashMap<String, dObject>();

        dPlayer player = new dPlayer(event.getPlayer());
        Sign sign = (Sign) block.getState();
        dLocation location = new dLocation(block.getLocation());
        dMaterial material = dMaterial.getMaterialFrom(block.getType(), block.getData());

        context.put("old", new dList(Arrays.asList(sign.getLines())));
        context.put("new", new dList(Arrays.asList(event.getLines())));

        dList old_escaped = new dList();
View Full Code Here

TOP

Related Classes of org.bukkit.block.Block

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.