Java Code Examples for org.bukkit.entity.ArmorStand#setHelmet()

The following examples show how to use org.bukkit.entity.ArmorStand#setHelmet() . 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: ArmorStandDisplayItem.java    From QuickShop-Reremake with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void safeGuard(@NotNull Entity entity) {
    if (!(entity instanceof ArmorStand)) {
        Util.debugLog(
                "Failed to safeGuard " + entity.getLocation() + ", cause target not a ArmorStand");
        return;
    }
    ArmorStand armorStand = (ArmorStand) entity;
    // Set item protect in the armorstand's hand
    this.guardedIstack = DisplayItem.createGuardItemStack(this.originalItemStack, this.shop);
    armorStand.setHelmet(guardedIstack);
    try {
        armorStand
                .getPersistentDataContainer()
                .set(
                        new NamespacedKey(plugin, "displayMark"),
                        DisplayItemPersistentDataType.INSTANCE,
                        DisplayItem.createShopProtectionFlag(this.originalItemStack, shop));
    } catch (Throwable ignored) {
    }
}
 
Example 2
Source File: MainListener.java    From ArmorStandTools with MIT License 6 votes vote down vote up
private ArmorStand spawnArmorStand(Location l) {
    ArmorStand as = (ArmorStand) l.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
    as.setHelmet(Config.helmet);
    as.setChestplate(Config.chest);
    as.setLeggings(Config.pants);
    as.setBoots(Config.boots);
    as.getEquipment().setItemInMainHand(Config.itemInHand);
    as.getEquipment().setItemInOffHand(Config.itemInOffHand);
    as.setVisible(Config.isVisible);
    as.setSmall(Config.isSmall);
    as.setArms(Config.hasArms);
    as.setBasePlate(Config.hasBasePlate);
    as.setGravity(Config.hasGravity);
    as.setInvulnerable(Config.invulnerable);
    if(Config.defaultName.length() > 0) {
        as.setCustomName(Config.defaultName);
        as.setCustomNameVisible(true);
    }
    Main.nms.setSlotsDisabled(as, Config.equipmentLock);
    return as;
}
 
Example 3
Source File: MainListener.java    From ArmorStandTools with MIT License 4 votes vote down vote up
@EventHandler
public void onSignChange(final SignChangeEvent event) {
    if(event.getBlock().hasMetadata("armorStand")) {
        final Block b = event.getBlock();
        final ArmorStand as = getArmorStand(b);
        if (as != null) {
            StringBuilder sb = new StringBuilder();
            for (String line : event.getLines()) {
                if (line != null && line.length() > 0) {
                    sb.append(ChatColor.translateAlternateColorCodes('&', line));
                }
            }
            String input = sb.toString();
            if(b.hasMetadata("setName")) {
                if (input.length() > 0) {
                    as.setCustomName(input);
                    as.setCustomNameVisible(true);
                } else {
                    as.setCustomName("");
                    as.setCustomNameVisible(false);
                    as.setCustomNameVisible(false);
                }
            } else if(b.hasMetadata("setSkull")) {
                if(MC_USERNAME_PATTERN.matcher(input).matches()) {
                    b.setMetadata("protected", new FixedMetadataValue(plugin, true));
                    event.getPlayer().sendMessage(ChatColor.GOLD + Config.pleaseWait);
                    String cmd = "minecraft:give " + event.getPlayer().getName() + " minecraft:player_head{SkullOwner:\"" + input + "\"} 1";
                    String current = b.getWorld().getGameRuleValue("sendCommandFeedback");
                    b.getWorld().setGameRuleValue("sendCommandFeedback", "false");
                    Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd);
                    b.getWorld().setGameRuleValue("sendCommandFeedback", current);
                    boolean found = false;
                    for(int slot : event.getPlayer().getInventory().all(Material.PLAYER_HEAD).keySet()) {
                        ItemStack skull = event.getPlayer().getInventory().getItem(slot);
                        SkullMeta sm = (SkullMeta) skull.getItemMeta();
                        if(sm.hasOwner() && input.equalsIgnoreCase(sm.getOwningPlayer().getName())) {
                            as.setHelmet(skull);
                            event.getPlayer().sendMessage(ChatColor.GREEN + Config.appliedHead + ChatColor.GOLD + " " + input);
                            event.getPlayer().getInventory().setItem(slot, null);
                            found = true;
                            break;
                        }
                    }
                    if(!found) {
                        event.getPlayer().sendMessage(ChatColor.GOLD + Config.headFailed);
                    }
                } else {
                    event.getPlayer().sendMessage(ChatColor.RED + input + " " + Config.invalidName);
                }
            }
        }
        event.setCancelled(true);
        b.removeMetadata("armorStand", plugin);
        b.removeMetadata("setName", plugin);
        b.removeMetadata("setSkull", plugin);
        b.setType(Material.AIR);
    }
}
 
Example 4
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:
        }
    }
}