org.bukkit.util.EulerAngle Java Examples

The following examples show how to use org.bukkit.util.EulerAngle. 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: ArmorStandFactory.java    From CS-CoreLib with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: AnglesCommand.java    From AstralEdit with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: DisplayArmorstand.java    From AstralEdit with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example #4
Source File: DisplayArmorstand.java    From AstralEdit with Apache License 2.0 5 votes vote down vote up
/**
 * 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());
    }
}
 
Example #5
Source File: SelectionManager.java    From AstralEdit with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
private static Rotations toNMS(EulerAngle old) {
    return new Rotations(
            (float) Math.toDegrees(old.getX()),
            (float) Math.toDegrees(old.getY()),
            (float) Math.toDegrees(old.getZ())
    );
}
 
Example #7
Source File: ArmorStandDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@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));
    }
}
 
Example #8
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setBodyPose(EulerAngle pose) {
    getHandle().setBodyRotation(toNMS(pose));
}
 
Example #9
Source File: DeathStandsModule.java    From UHC with MIT License 4 votes vote down vote up
@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:
        }
    }
}
 
Example #10
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EulerAngle getLeftArmPose() {
    return fromNMS(getHandle().leftArmRotation);
}
 
Example #11
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setLeftArmPose(EulerAngle pose) {
    getHandle().setLeftArmRotation(toNMS(pose));
}
 
Example #12
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EulerAngle getRightArmPose() {
    return fromNMS(getHandle().rightArmRotation);
}
 
Example #13
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setRightArmPose(EulerAngle pose) {
    getHandle().setRightArmRotation(toNMS(pose));
}
 
Example #14
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EulerAngle getRightLegPose() {
    return fromNMS(getHandle().rightLegRotation);
}
 
Example #15
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setRightLegPose(EulerAngle pose) {
    getHandle().setRightLegRotation(toNMS(pose));
}
 
Example #16
Source File: CraftArmorStand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setHeadPose(EulerAngle pose) {
    getHandle().setHeadRotation(toNMS(pose));
}
 
Example #17
Source File: PacketArmorstand.java    From AstralEdit with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the pose of the head
 *
 * @return angle
 */
EulerAngle getHeadPose();
 
Example #18
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setRightLegPose(EulerAngle pose) {

}
 
Example #19
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setLeftLegPose(EulerAngle pose) {

}
 
Example #20
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setHeadPose(EulerAngle pose) {

}
 
Example #21
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setRightLegPose(EulerAngle pose) {

}
 
Example #22
Source File: PacketArmorstand.java    From AstralEdit with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the pose of
 *
 * @param angle angle
 */
void setHeadPose(EulerAngle angle);
 
Example #23
Source File: LocationBuilder.java    From AstralEdit with Apache License 2.0 2 votes vote down vote up
/**
 * Converts the builder to a bukkitEulerAngle
 *
 * @return eulerAngle
 */
public EulerAngle toAngle() {
    return new EulerAngle(this.x, this.y, this.z);
}
 
Example #24
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setLeftLegPose(EulerAngle pose) {

}
 
Example #25
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setBodyPose(EulerAngle pose) {

}
 
Example #26
Source File: DisplayArmorstand.java    From AstralEdit with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the pose of
 *
 * @param angle angle
 */
@Override
public void setHeadPose(EulerAngle angle) {
    ((ArmorStand) this.armorStand.getBukkitEntity()).setHeadPose(angle);
}
 
Example #27
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setBodyPose(EulerAngle pose) {

}
 
Example #28
Source File: DisplayArmorstand.java    From AstralEdit with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the pose of the head
 *
 * @return angle
 */
@Override
public EulerAngle getHeadPose() {
    return ((ArmorStand) this.armorStand.getBukkitEntity()).getHeadPose();
}
 
Example #29
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setLeftArmPose(EulerAngle pose) {

}
 
Example #30
Source File: CraftNameable.java    From Holograms with MIT License 2 votes vote down vote up
@Override
public void setBodyPose(EulerAngle pose) {

}