下面列出了org.bukkit.block.BlockFace#valueOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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]));
}
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());
}
@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();
}
}
public BlockFace getBlockFace(String param) {
BlockFace face = null;
try {
face = BlockFace.valueOf(param.toUpperCase());
} catch (IllegalArgumentException e) {
// ignore
}
return face;
}
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;
}
/**
* 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;
}
}
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));
}
}
}
}