@EventHandler public void onVehicleImpact(CartBlockImpactEvent event) { // validate if (!event.getBlocks().matches(getMaterial())) return; if (!event.getBlocks().hasSign()) return; if (event.isMinor()) return; if (!(event.getBlocks().matches("cartlift up") || event.getBlocks().matches("cartlift down"))) return; Minecart cart = (Minecart) event.getVehicle(); // go boolean up = event.getBlocks().matches("cartlift up"); Block destination = event.getBlocks().sign; BlockFace face; if (up) face = BlockFace.UP; else face = BlockFace.DOWN; while (true) { if (destination.getLocation().getBlockY() <= 0 && !up) return; if (destination.getLocation().getBlockY() >= destination.getWorld().getMaxHeight() - 1 && up) return; destination = destination.getRelative(face); if (SignUtil.isSign(destination) && event.getBlocks().base.getTypeId() == destination.getRelative(BlockFace.UP, 1).getTypeId()) { ChangedSign state = BukkitUtil.toChangedSign(destination); String testLine = state.getLine(1); if (testLine.equalsIgnoreCase("[CartLift Up]") || testLine.equalsIgnoreCase("[CartLift Down]") || testLine.equalsIgnoreCase("[CartLift]")) { destination = destination.getRelative(BlockFace.UP, 2); break; } } } CartUtils.teleport( cart, new Location( destination.getWorld(), destination.getX(), destination.getY(), destination.getZ(), cart.getLocation().getYaw(), cart.getLocation().getPitch())); }
@Command( aliases = "toggle", desc = "Toggle an area sign at the given location.", usage = "[-w world] <x,y,z>", flags = "sw:", min = 1) @CommandPermissions("craftbook.mech.area.command.toggle") public void toggle(CommandContext context, CommandSender sender) throws CommandException { World world = null; boolean hasWorldFlag = context.hasFlag('w'); if (hasWorldFlag) { world = Bukkit.getWorld(context.getFlag('w')); } else if (sender instanceof Player) { world = ((Player) sender).getWorld(); } if (world == null) { throw new CommandException( "You must be a player or specify a valid world to use this command."); } int[] xyz = new int[3]; String[] loc = context.getString(0).split(","); if (loc.length != 3) { throw new CommandException("Invalid location specified."); } try { for (int i = 0; i < xyz.length; i++) { xyz[i] = Integer.parseInt(loc[i]); } } catch (NumberFormatException ex) { throw new CommandException("Invalid location specified."); } Block block = world.getBlockAt(xyz[0], xyz[1], xyz[2]); if (!SignUtil.isSign(block)) throw new CommandException("No sign found at the specified location."); if (!Area.toggleCold(BukkitUtil.toChangedSign(block))) { throw new CommandException("Failed to toggle an area at the specified location."); } // TODO Make a sender wrap for this if (!context.hasFlag('s')) sender.sendMessage(ChatColor.YELLOW + "Area toggled!"); }
@Override public void trigger(ChipState chip) { if (!location.getChunk().isLoaded()) return; if (!chip.getInput(0)) return; Block left = SignUtil.getLeftBlock(BukkitUtil.toSign(getSign()).getBlock()); ChangedSign effectSign = null; if (left.getTypeId() == BlockID.WALL_SIGN) { effectSign = BukkitUtil.toChangedSign(left); } Block right = SignUtil.getRightBlock(BukkitUtil.toSign(getSign()).getBlock()); ChangedSign armourSign = null; if (right.getTypeId() == BlockID.WALL_SIGN) { armourSign = BukkitUtil.toChangedSign(right); } for (int i = 0; i < amount; i++) { Entity ent = BukkitUtil.toSign(getSign()).getWorld().spawn(location, type.getEntityClass()); if (armourSign != null) { // Apply armor if (ent instanceof LivingEntity) { for (int s = 0; s < 4; s++) { String bit = armourSign.getLine(s); ItemStack slot = ItemUtil.makeItemValid(ItemUtil.getItem(bit)); if (s == 0) ((LivingEntity) ent).getEquipment().setHelmet(slot); if (s == 1) ((LivingEntity) ent).getEquipment().setChestplate(slot); if (s == 2) ((LivingEntity) ent).getEquipment().setLeggings(slot); if (s == 3) ((LivingEntity) ent).getEquipment().setBoots(slot); } } } Boolean upwards = null; while (effectSign != null) { // Apply effects for (int s = 0; s < 4; s++) { String bit = effectSign.getLine(s); if (bit == null || bit.trim().isEmpty()) continue; String[] data = RegexUtil.COLON_PATTERN.split(bit); if (data[0].equalsIgnoreCase("e")) CreatureSpawner.setEntityData(ent, bit.substring(2)); else if (data[0].equalsIgnoreCase("r")) { EntityType rider = EntityType.fromName(data[1].trim()); Entity rid = BukkitUtil.toSign(getSign()).getWorld().spawnEntity(location, rider); ent.setPassenger(rid); } else if (data[0].equalsIgnoreCase("p") && ent instanceof LivingEntity) { for (int a = 1; a < data.length; a++) { try { String[] potionBits = RegexUtil.SEMICOLON_PATTERN.split(data[a]); PotionEffect effect = new PotionEffect( PotionEffectType.getById(Integer.parseInt(potionBits[0])), Integer.parseInt(potionBits[1]), Integer.parseInt(potionBits[2])); ((LivingEntity) ent).addPotionEffect(effect, true); } catch (Exception e) { } } } else if (data[0].equalsIgnoreCase("v")) { try { double x, y, z; String[] coords = RegexUtil.COMMA_PATTERN.split(data[1]); x = Double.parseDouble(coords[0]); y = Double.parseDouble(coords[1]); z = Double.parseDouble(coords[2]); ent.setVelocity(new org.bukkit.util.Vector(x, y, z)); } catch (Exception ignored) { } } else if (data[0].equalsIgnoreCase("s")) { if (!(ent instanceof LivingEntity)) continue; ItemStack slot = ItemUtil.makeItemValid(ItemUtil.getItem(bit.replace("s:", ""))); ((LivingEntity) ent).getEquipment().setItemInHand(slot); } } if (upwards == null) { if (BukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0).getTypeId() == BlockID.WALL_SIGN) { effectSign = BukkitUtil.toChangedSign( BukkitUtil.toSign(effectSign).getBlock().getRelative(0, 1, 0)); upwards = true; } else if (BukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0).getTypeId() == BlockID.WALL_SIGN) { effectSign = BukkitUtil.toChangedSign( BukkitUtil.toSign(effectSign).getBlock().getRelative(0, -1, 0)); upwards = false; } else break; } else { if (BukkitUtil.toSign(effectSign) .getBlock() .getRelative(0, upwards ? 1 : -1, 0) .getTypeId() == BlockID.WALL_SIGN) effectSign = BukkitUtil.toChangedSign( BukkitUtil.toSign(effectSign).getBlock().getRelative(0, upwards ? 1 : -1, 0)); else break; } } } }