@Override void onRightClick() { as = getPlayer().getWorld().spawn(getPlayer().getLocation(), ArmorStand.class); as.setGravity(false); as.setSmall(true); running = true; as.setVisible(false); as.setHelmet(new ItemStack(Material.SEA_LANTERN)); Bukkit.getScheduler() .runTaskLater( UltraCosmetics.getInstance(), new Runnable() { @Override public void run() { as.remove(); as = null; Bukkit.getScheduler() .runTaskLater( UltraCosmetics.getInstance(), new Runnable() { @Override public void run() { running = false; } }, 20); } }, 220); }
@EventHandler public void onKick(PlayerKickEvent event) { try { if (running) { if (as != null && as.isValid() && event.getReason().contains("Fly")) { if (as.getLocation().distance(event.getPlayer().getLocation()) < 8) { event.setCancelled(true); System.out.println("UltraCosmetics >> Cancelling invalid Flight KicK."); return; } } event.setCancelled(true); System.out.println("UltraCosmetics >> Cancelling invalid Flight KicK."); return; } } catch (Exception exc) { } }
@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode) { Entity ent = getExpr().getSingle(e); // Called to get the Target which is Player in this case. if (ent == null) return; if (ent.getType() != EntityType.ARMOR_STAND) { return; } Boolean b = (Boolean) (delta[0]); if (mode == Changer.ChangeMode.SET) { ((ArmorStand) ent).setSmall(b); } }
@EventHandler(ignoreCancelled = true) public void onNPCSpawn(NPCSpawnEvent event) { String name = getData(event.getData(), NPCProperties.NAME, String.class); if (name == null) { return; } Preconditions.checkArgument(!name.isEmpty(), "name cannot be empty."); Entity npc = event.getNpc(); ArmorStand armorStand = (ArmorStand) npcManager.spawn(this.blankNametag, npc.getLocation()); if (armorStand == null) { warn("ArmorStand for %s could not be spawned.", event.getData().getId()); return; } armorStand.setCustomName(name); armorStand.setMetadata( nametagMetadata, new FixedMetadataValue(this.npcManager.getOwner(), npc.getEntityId())); this.datas.put(npc, new NameData(npc, armorStand)); if (this.task == null) { this.task = new ArmorStandTask(); } }
@Override void onUpdate() { if (as != null && as.isValid()) { as.setHeadPose(as.getHeadPose().add(0, 0.1, 0)); UtilParticles.display(Particles.PORTAL, 3f, 3f, 3f, as.getLocation(), 150); UtilParticles.display(Particles.SPELL_WITCH, .3f, .3f, .3f, as.getEyeLocation(), 5); for (Entity ent : as.getNearbyEntities(3, 2, 3)) { if (ent instanceof LivingEntity && !(ent instanceof ArmorStand)) MathUtils.applyVelocity(ent, new Vector(0, 0.05, 0)); } } }
@Override public void change(Event e, Object[] delta, Changer.ChangeMode mode) { Entity ent = getExpr().getSingle(e); // Called to get the Target which is Player in this case. if (ent == null) return; if (ent.getType() != EntityType.ARMOR_STAND) { return; } Number b = (Number) (delta[0]); if (mode == Changer.ChangeMode.SET) { ArmorStand as = (ArmorStand) ent; ((ArmorStand) ent).setLeftArmPose(as.getLeftArmPose().setZ(b.doubleValue())); } if (mode == Changer.ChangeMode.ADD) { ArmorStand as = (ArmorStand) ent; ((ArmorStand) ent) .setLeftArmPose(as.getLeftArmPose().setZ(as.getLeftArmPose().getZ() + b.doubleValue())); } if (mode == Changer.ChangeMode.REMOVE) { ArmorStand as = (ArmorStand) ent; ((ArmorStand) ent) .setLeftArmPose(as.getLeftArmPose().setZ(as.getLeftArmPose().getZ() - b.doubleValue())); } }
@Override public void onClear() { if (as != null) as.remove(); HandlerList.unregisterAll(this); }