Java Code Examples for org.bukkit.block.BlockFace#valueOf()

The following examples show how to use org.bukkit.block.BlockFace#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnniSign.java    From AnnihilationPro with MIT License 6 votes vote down vote up
public AnniSign(ConfigurationSection configSection)
{
	if(configSection == null)
		throw new NullPointerException();
	
	boolean signpost = configSection.getBoolean("isSignPost");
	//Location loc = ConfigManager.getLocation(configSection.getConfigurationSection("Location"));
	Loc loc = new Loc(configSection.getConfigurationSection("Location"));
	BlockFace facing = BlockFace.valueOf(configSection.getString("FacingDirection"));	
	obj = new FacingObject(facing, loc);
	this.signPost = signpost;
	String data = configSection.getString("Data");
	if(data.equalsIgnoreCase("Brewing"))
		type = SignType.Brewing;
	else if(data.equalsIgnoreCase("Weapon"))
		type = SignType.Weapon;
	else
		type = SignType.newTeamSign(AnniTeam.getTeamByName(data.split("-")[1]));
}
 
Example 2
Source File: ProgrammableAndroid.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
protected void rotate(Block b, int mod) {
    BlockFace current = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));
    int index = POSSIBLE_ROTATIONS.indexOf(current) + mod;

    if (index == POSSIBLE_ROTATIONS.size()) {
        index = 0;
    }
    else if (index < 0) {
        index = POSSIBLE_ROTATIONS.size() - 1;
    }

    BlockFace rotation = POSSIBLE_ROTATIONS.get(index);

    Rotatable rotatatable = (Rotatable) b.getBlockData();
    rotatatable.setRotation(rotation);
    b.setBlockData(rotatatable);
    BlockStorage.addBlockInfo(b, "rotation", rotation.name());
}
 
Example 3
Source File: SignShop.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void load(ConfigurationSection config) {
	super.load(config);
	if (config.isString("signFacing")) {
		String signFacingName = config.getString("signFacing");
		if (signFacingName != null) {
			try {
				signFacing = BlockFace.valueOf(signFacingName);
			} catch (IllegalArgumentException e) {
			}
		}
	}

	// in case no sign facing is stored: try getting the current sign facing from sign in the world
	// if it is not possible (for ex. because the world isn't loaded yet), we will reattempt this
	// during the periodically checks
	if (signFacing == null) {
		signFacing = this.getSignFacingFromWorld();
	}
}
 
Example 4
Source File: PlayerUtil.java    From GriefDefender with MIT License 5 votes vote down vote up
public BlockFace getBlockFace(String param) {
    BlockFace face = null;
    try {
        face = BlockFace.valueOf(param.toUpperCase());
    } catch (IllegalArgumentException e) {
        // ignore
    }
    return face;
}
 
Example 5
Source File: FacingObject.java    From AnnihilationPro with MIT License 5 votes vote down vote up
public static FacingObject loadFromConfig(ConfigurationSection configSection)
{
	if(configSection != null)
	{
		//Location loc = ConfigManager.getLocation(configSection.getConfigurationSection("Location"));
		Loc loc = new Loc(configSection.getConfigurationSection("Location"));
		BlockFace facing = BlockFace.valueOf(configSection.getString("FacingDirection"));
		return new FacingObject(facing,loc);
	}
	return null;
}
 
Example 6
Source File: RegionSign.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the facing of the sign as saved in the config.
 * @return BlockFace the sign faces, or null if unknown
 */
public BlockFace getFacing() {
	try {
		return BlockFace.valueOf(getRegion().getConfig().getString("general.signs." + key + ".facing"));
	} catch(NullPointerException | IllegalArgumentException e) {
		return null;
	}
}
 
Example 7
Source File: ProgrammableAndroid.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
protected void tick(Block b) {
    if (b.getType() != Material.PLAYER_HEAD) {
        // The Android was destroyed or moved.
        return;
    }

    if ("false".equals(BlockStorage.getLocationInfo(b.getLocation(), "paused"))) {
        BlockMenu menu = BlockStorage.getInventory(b);
        float fuel = Float.parseFloat(BlockStorage.getLocationInfo(b.getLocation(), "fuel"));

        if (fuel < 0.001) {
            consumeFuel(b, menu);
        }
        else {
            String[] script = PatternUtils.DASH.split(BlockStorage.getLocationInfo(b.getLocation(), "script"));

            int index = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "index")) + 1;
            if (index >= script.length) {
                index = 0;
            }

            boolean refresh = true;
            BlockStorage.addBlockInfo(b, "fuel", String.valueOf(fuel - 1));
            Instruction instruction = Instruction.valueOf(script[index]);

            if (getAndroidType().isType(instruction.getRequiredType())) {
                BlockFace face = BlockFace.valueOf(BlockStorage.getLocationInfo(b.getLocation(), "rotation"));

                switch (instruction) {
                case START:
                case WAIT:
                    // Just "waiting" here which means we do nothing
                    break;
                case REPEAT:
                    BlockStorage.addBlockInfo(b, "index", String.valueOf(0));
                    break;
                case CHOP_TREE:
                    refresh = chopTree(b, menu, face);
                    break;
                default:
                    instruction.execute(this, b, menu, face);
                    break;
                }
            }

            if (refresh) {
                BlockStorage.addBlockInfo(b, "index", String.valueOf(index));
            }
        }
    }
}