下面列出了怎么用org.bukkit.Rotation的API类实例代码及写法,或者点击链接到github查看源代码。
Rotation toBukkitRotation(int value) {
// Translate NMS rotation integer to Bukkit API
switch (value) {
case 0:
return Rotation.NONE;
case 1:
return Rotation.CLOCKWISE_45;
case 2:
return Rotation.CLOCKWISE;
case 3:
return Rotation.CLOCKWISE_135;
case 4:
return Rotation.FLIPPED;
case 5:
return Rotation.FLIPPED_45;
case 6:
return Rotation.COUNTER_CLOCKWISE;
case 7:
return Rotation.COUNTER_CLOCKWISE_45;
default:
throw new AssertionError("Unknown rotation " + value + " for " + getHandle());
}
}
static int toInteger(Rotation rotation) {
// Translate Bukkit API rotation to NMS integer
switch (rotation) {
case NONE:
return 0;
case CLOCKWISE_45:
return 1;
case CLOCKWISE:
return 2;
case CLOCKWISE_135:
return 3;
case FLIPPED:
return 4;
case FLIPPED_45:
return 5;
case COUNTER_CLOCKWISE:
return 6;
case COUNTER_CLOCKWISE_45:
return 7;
default:
throw new IllegalArgumentException(rotation + " is not applicable to an ItemFrame");
}
}
Rotation toBukkitRotation(int value) {
// Translate NMS rotation integer to Bukkit API
switch (value) {
case 0:
return Rotation.NONE;
case 1:
return Rotation.CLOCKWISE;
case 2:
return Rotation.FLIPPED;
case 3:
return Rotation.COUNTER_CLOCKWISE;
default:
throw new AssertionError("Unknown rotation " + value + " for " + getHandle());
}
}
static int toInteger(Rotation rotation) {
// Translate Bukkit API rotation to NMS integer
switch (rotation) {
case NONE:
return 0;
case CLOCKWISE:
return 1;
case FLIPPED:
return 2;
case COUNTER_CLOCKWISE:
return 3;
default:
throw new IllegalArgumentException(rotation + " is not applicable to an ItemFrame");
}
}
private ItemFrame[][] find(Location pos1, Location pos2, BlockFace facing) {
try {
Location distance = pos2.clone().subtract(pos1).add(1, 1, 1);
int width = Math.max(distance.getBlockX(), distance.getBlockZ());
ItemFrame[][] frames = new ItemFrame[width][distance.getBlockY()];
World world = pos1.getWorld();
this.reverse = (facing == BlockFace.NORTH || facing == BlockFace.EAST);
int v = 0;
for (double y = pos1.getY(); y <= pos2.getY(); y++, v++) {
int h = 0;
for (double z = pos1.getZ(); z <= pos2.getZ(); z++) {
for (double x = pos1.getX(); x <= pos2.getX(); x++, h++) {
Location pos = new Location(world, x, y, z);
Collection<Entity> entities = world.getNearbyEntities(pos, 0.1, 0.1, 0.1);
boolean contains = false;
for (Entity ent : entities) {
if (ent instanceof ItemFrame && ((ItemFrame) ent).getFacing() == facing) {
ItemFrame itemFrame = (ItemFrame) ent;
itemFrame.setRotation(Rotation.NONE);
contains = true;
frames[reverse ? width - 1 - h : h][v] = (ItemFrame) ent;
break;
}
}
if (!contains) return null;
}
}
}
return frames;
} catch (Throwable e) {
e.printStackTrace();
}
return null;
}
public Rotation getRotation() {
return toBukkitRotation(getHandle().getRotation());
}
public void setRotation(Rotation rotation) {
Validate.notNull(rotation, "Rotation cannot be null");
getHandle().setItemRotation(toInteger(rotation));
}
public Rotation getRotation() {
return toBukkitRotation(getHandle().getRotation());
}
public void setRotation(Rotation rotation) {
Validate.notNull(rotation, "Rotation cannot be null");
getHandle().setItemRotation(toInteger(rotation));
}
/**
* Get the rotation of the frame's item
*
* @return the direction
*/
public Rotation getRotation();
/**
* Set the rotation of the frame's item
*
* @param rotation the new rotation
* @throws IllegalArgumentException if rotation is null
*/
public void setRotation(Rotation rotation) throws IllegalArgumentException;