下面列出了org.bukkit.craftbukkit.v1_8_R3.CraftWorld#org.bukkit.util.EulerAngle 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Executes the given command if the arguments match.
*
* @param player executing the command.
* @param args arguments.
* @return True if this command was executed. False if the arguments do not match.
*/
@Override
public boolean onPlayerExecuteCommand(Player player, String[] args) {
if (args.length != 4 || !args[0].equalsIgnoreCase("angles") ||
!tryParseDouble(args[1]) || !tryParseDouble(args[2]) || !tryParseDouble(args[3]) ||
!Permission.ANGLES.hasPermission(player)) {
return false;
}
this.plugin.getServer().getScheduler().runTaskAsynchronously(this.plugin, () -> {
if (!this.manager.hasSelection(player)) {
player.sendMessage(AstralEditPlugin.PREFIX_ERROR + "You don't have a valid render.");
} else {
final Operation operation = new Operation(OperationType.ANGLES);
operation.setOperationData(this.manager.getSelection(player).getBlockAngle());
this.manager.getSelection(player).setBlockAngle(new EulerAngle(Double.parseDouble(args[1]), Double.parseDouble(args[2]), Double.parseDouble(args[3])));
this.manager.addOperation(player, operation);
}
});
return true;
}
public static ArmorStand createSmall(Location l, ItemStack item, EulerAngle arm, float yaw) {
l.setYaw(yaw);
ArmorStand armorStand = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
armorStand.getEquipment().setItemInMainHand(item);
armorStand.setVisible(false);
armorStand.setSilent(true);
armorStand.setMarker(true);
armorStand.setGravity(false);
armorStand.setSmall(true);
armorStand.setArms(true);
armorStand.setRightArmPose(arm);
armorStand.setBasePlate(false);
armorStand.setRemoveWhenFarAway(false);
return armorStand;
}
@Deprecated // no use, will be removed soon
private void setPoseForArmorStand() {
if (this.originalItemStack.getType().isBlock()) {
Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-0.2, 0, 0));
} else {
Objects.requireNonNull(armorStand).setRightArmPose(new EulerAngle(-89.5, 0, 0));
}
}
private static Rotations toNMS(EulerAngle old) {
return new Rotations(
(float) Math.toDegrees(old.getX()),
(float) Math.toDegrees(old.getY()),
(float) Math.toDegrees(old.getZ())
);
}
/**
* Undos an operation
*
* @param player player
*/
public boolean undoOperation(Player player) {
if (!this.hasSelection(player))
return false;
if (!this.operations.containsKey(player))
this.operations.put(player, new Operation[this.maxUndoAmount]);
final Operation operation = this.operations.get(player)[0];
if (operation != null) {
if (operation.getType() == OperationType.MIRROR) {
this.getSelection(player).mirror();
} else if (operation.getType() == OperationType.FLIP) {
this.getSelection(player).flip();
} else if (operation.getType() == OperationType.UPSIDEDOWN) {
this.getSelection(player).upSideDown();
} else if (operation.getType() == OperationType.UNCOMBINE) {
this.getSelection(player).join();
} else if (operation.getType() == OperationType.COMBINE) {
this.getSelection(player).tearApart();
} else if (operation.getType() == OperationType.ROTATE) {
this.selections.get(player).unSecureRotate((Double) operation.getOperationData());
} else if (operation.getType() == OperationType.ANGLES) {
this.getSelection(player).setBlockAngle((EulerAngle) operation.getOperationData());
} else if (operation.getType() == OperationType.PLACE || operation.getType() == OperationType.CONVERTOBLOCKS) {
final List<Container> containers = (List<Container>) operation.getOperationData();
Bukkit.getServer().getScheduler().runTask(JavaPlugin.getPlugin(AstralEditPlugin.class), () -> this.placeUndoCalc(0, containers.get(0), containers, 0));
} else if (operation.getType() == OperationType.MOVE) {
this.selections.get(player).teleport((Location) operation.getOperationData());
}
this.removeOperation(player);
return true;
}
return false;
}
/**
* Initializes the armorstand
*
* @param player player
* @param location location
* @param id id
* @param data data
* @param watchers watchers
*/
public DisplayArmorstand(Player player, Location location, int id, byte data, Set<Player> watchers) {
super();
this.watchers = watchers;
this.player = player;
this.armorStand = new EntityArmorStand(((CraftWorld) player.getWorld()).getHandle());
final NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("invulnerable", true);
compound.setBoolean("Invisible", true);
compound.setBoolean("PersistenceRequired", true);
compound.setBoolean("NoBasePlate", true);
this.armorStand.a(compound);
this.armorStand.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
this.storedId = id;
this.storedData = data;
ItemStackBuilder stackBuilder = new ItemStackBuilder(Material.getMaterial(id), 1, data);
this.getCraftEntity().setHelmet(stackBuilder.build());
this.getCraftEntity().setBodyPose(new EulerAngle(3.15, 0, 0));
this.getCraftEntity().setLeftLegPose(new EulerAngle(3.15, 0, 0));
this.getCraftEntity().setRightLegPose(new EulerAngle(3.15, 0, 0));
if (((ArmorStand) this.armorStand.getBukkitEntity()).getHelmet().getType() == Material.AIR) {
stackBuilder = new ItemStackBuilder(Material.SKULL_ITEM, 1, (short) 3);
if (id == Material.WATER.getId() || id == Material.STATIONARY_WATER.getId()) {
stackBuilder.setSkin(NMSRegistry.WATER_HEAD);
} else if (id == Material.LAVA.getId() || id == Material.STATIONARY_LAVA.getId()) {
stackBuilder.setSkin(NMSRegistry.LAVA_HEAD);
} else {
stackBuilder.setSkin(NMSRegistry.NOT_FOUND);
}
((ArmorStand) this.armorStand.getBukkitEntity()).setHelmet(stackBuilder.build());
}
}
/**
* Initializes the armorstand
*
* @param player player
* @param location location
* @param id id
* @param data data
* @param watchers watchers
*/
public DisplayArmorstand(Player player, Location location, int id, byte data, Set<Player> watchers) {
super();
this.watchers = watchers;
this.player = player;
this.armorStand = new EntityArmorStand(((CraftWorld) player.getWorld()).getHandle());
final NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("invulnerable", true);
compound.setBoolean("Invisible", true);
compound.setBoolean("PersistenceRequired", true);
compound.setBoolean("NoBasePlate", true);
this.armorStand.a(compound);
this.armorStand.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
this.storedId = id;
this.storedData = data;
ItemStackBuilder stackBuilder = new ItemStackBuilder(Material.getMaterial(id), 1, data);
this.getCraftEntity().setHelmet(stackBuilder.build());
this.getCraftEntity().setBodyPose(new EulerAngle(3.15, 0, 0));
this.getCraftEntity().setLeftLegPose(new EulerAngle(3.15, 0, 0));
this.getCraftEntity().setRightLegPose(new EulerAngle(3.15, 0, 0));
if (((ArmorStand) this.armorStand.getBukkitEntity()).getHelmet().getType() == Material.AIR) {
stackBuilder = new ItemStackBuilder(Material.SKULL_ITEM, 1, (short) 3);
if (id == Material.WATER.getId() || id == Material.STATIONARY_WATER.getId()) {
stackBuilder.setSkin(NMSRegistry.WATER_HEAD);
} else if (id == Material.LAVA.getId() || id == Material.STATIONARY_LAVA.getId()) {
stackBuilder.setSkin(NMSRegistry.LAVA_HEAD);
} else {
stackBuilder.setSkin(NMSRegistry.NOT_FOUND);
}
((ArmorStand) this.armorStand.getBukkitEntity()).setHelmet(stackBuilder.build());
}
}
@EventHandler(priority = EventPriority.HIGH)
public void on(PlayerDeathEvent event) {
if (!isEnabled()) return;
final Player player = event.getEntity();
// make the player invisible for the duration of their death animation
player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, DEATH_ANIMATION_TIME, 1));
final Location location = player.getLocation();
// create an armour stand at the player
final ArmorStand stand = player.getWorld().spawn(location.clone().add(0, .2D, 0), ArmorStand.class);
stand.setBasePlate(false);
stand.setArms(true);
// give the armour stand the death message as a name
stand.setCustomName(STAND_PREFIX + event.getDeathMessage());
stand.setCustomNameVisible(true);
// face the same direction as the player
stand.getLocation().setDirection(location.getDirection());
// set the armour stand helmet to be looking at the same yaw
stand.setHeadPose(new EulerAngle(Math.toRadians(location.getPitch()), 0, 0));
// use the player's velocity as a base and apply it to the stand
stand.setVelocity(
player.getVelocity()
.clone()
.multiply(PLAYER_VELOCITY_MULTIPLIER)
.add(new Vector(0D, PLAYER_VELOICY_Y_ADDITIONAL, 0D))
);
// start with player's existing items in each slot (if exists)
Map<EquipmentSlot, ItemStack> toSet = getItems(player.getInventory());
// overide with any saved items in the metadata
toSet.putAll(getSavedSlots(player));
// filter out the invalid items
toSet = Maps.filterValues(toSet, Predicates.not(EMPTY_ITEM));
final List<ItemStack> drops = event.getDrops();
for (final Map.Entry<EquipmentSlot, ItemStack> entry : toSet.entrySet()) {
final ItemStack stack = entry.getValue();
if (stack == null) continue;
// remove the first matching stack in the drop list
removeFirstEquals(drops, stack);
// set the item on the armour stand in the correct slot
switch (entry.getKey()) {
case HAND:
stand.setItemInHand(stack);
break;
case HEAD:
stand.setHelmet(stack);
break;
case CHEST:
stand.setChestplate(stack);
break;
case LEGS:
stand.setLeggings(stack);
break;
case FEET:
stand.setBoots(stack);
break;
default:
}
}
}
@Override
public void setBodyPose(EulerAngle pose) {
getHandle().setBodyRotation(toNMS(pose));
}
@Override
public EulerAngle getLeftArmPose() {
return fromNMS(getHandle().leftArmRotation);
}
@Override
public void setLeftArmPose(EulerAngle pose) {
getHandle().setLeftArmRotation(toNMS(pose));
}
@Override
public EulerAngle getRightArmPose() {
return fromNMS(getHandle().rightArmRotation);
}
@Override
public void setRightArmPose(EulerAngle pose) {
getHandle().setRightArmRotation(toNMS(pose));
}
@Override
public EulerAngle getRightLegPose() {
return fromNMS(getHandle().rightLegRotation);
}
@Override
public void setRightLegPose(EulerAngle pose) {
getHandle().setRightLegRotation(toNMS(pose));
}
@Override
public void setHeadPose(EulerAngle pose) {
getHandle().setHeadRotation(toNMS(pose));
}
@Override
public void setLeftArmPose(EulerAngle pose) {
}
/**
* Sets the armor stand's body's
* current pose as a {@link EulerAngle}
*
* @param pose the current pose
*/
void setBodyPose(EulerAngle pose);
@Override
public void setBodyPose(EulerAngle pose) {
}
@Override
public void setRightArmPose(EulerAngle pose) {
}
/**
* Returns the armor stand's right arm's
* current pose as a {@link EulerAngle}
*
* @return the current pose
*/
EulerAngle getRightArmPose();
@Override
public void setHeadPose(EulerAngle pose) {
}
@Override
public void setHeadPose(EulerAngle pose) {
}
/**
* Sets the armor stand's left leg's
* current pose as a {@link EulerAngle}
*
* @param pose the current pose
*/
void setLeftLegPose(EulerAngle pose);
/**
* Returns the armor stand's right leg's
* current pose as a {@link EulerAngle}
*
* @return the current pose
*/
EulerAngle getRightLegPose();
@Override
public void setLeftArmPose(EulerAngle pose) {
}
/**
* Returns the armor stand's head's
* current pose as a {@link EulerAngle}
*
* @return the current pose
*/
EulerAngle getHeadPose();
@Override
public void setRightArmPose(EulerAngle pose) {
}
@Override
public void setLeftArmPose(EulerAngle pose) {
}
@Override
public void setLeftArmPose(EulerAngle pose) {
}