Package org.cattech.bukkit

Source Code of org.cattech.bukkit.Common

package org.cattech.bukkit;

import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;

import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.cattech.bukkit.bigdig.DigSettings;
import org.cattech.bukkit.bigdig.VectorHelper;

public class Common {

  // Vector Modes
  public static final int  VECTOR_BY_PLAYER    = 1;
  public static final int  VECTOR_BY_TARGET    = 2;
  // Vector Constraints
  public static final int  CONSTRAIN_NONE      = 0;
  public static final int  CONSTRAIN_TO_HORIZONTAL  = 1;
  // Track Laying Modes
  public static final int  TRACK_MODE_NONE      = 0;
  public static final int  TRACK_MODE_FLAT      = 1;
  public static final int  TRACK_MODE_FOLLOW    = 2;
  public static final int  TRACK_MODE_BRIDGE    = 3;
 
  public Common() {
    super();
  }

  public boolean consumeItem(Player player, int itemID, Hashtable<String, String> messages) {
   
    PlayerInventory inventory = player.getInventory();
    boolean itemConsumed = false;
   
   
    int idx = inventory.first(itemID);
   
    if (idx >= 0) {
      ItemStack toConsume = inventory.getItem(idx);
      int amt = toConsume.getAmount();
      if (amt > 0) {
        itemConsumed = true;
        amt--;
        if (amt <= 0) {
          inventory.clear(idx);
        } else {
          toConsume.setAmount(amt);
        }
        DigSettings.setHadItem(player,itemID,true);
      }
    } else {
      boolean b = DigSettings.getHadItem(player,itemID);
      if (b) {
        messages.put("You are out of " + Material.getMaterial(itemID).toString().toLowerCase(), "send");
        DigSettings.setHadItem(player,itemID,false);
      }
    }

    return itemConsumed;
  }

  public List<Block> getLastTwoTargetBlocksVisible(Player player) {
    HashSet<Byte> transparent = new HashSet<Byte>();

    transparent.add((byte) Material.AIR.getId());
    transparent.add((byte) Material.STATIONARY_WATER.getId());
    transparent.add((byte) Material.WATER.getId());
    transparent.add((byte) Material.STATIONARY_LAVA.getId());
    transparent.add((byte) Material.LAVA.getId());

    return (List<Block>) player.getLastTwoTargetBlocks(transparent, 50);
  }

  public Block blockAtVec(World world, VectorHelper curVect) {
    return world.getBlockAt(curVect.getCoordX(), curVect.getCoordY(), curVect.getCoordZ());
  }

}
TOP

Related Classes of org.cattech.bukkit.Common

TOP
Copyright © 2018 www.massapi.com. 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.