コード例 #1
0
ファイル: EntityCannon.java プロジェクト: wizjany/craftbook
  /**
   * This method launches near by entities
   *
   * @return true if a entity was thrown.
   */
  protected boolean shoot() {

    boolean resultBoolean = false;
    Location location = BukkitUtil.toSign(getSign()).getLocation();
    EntityType type = EntityType.MOB_HOSTILE;

    if (!getSign().getLine(3).isEmpty()) {
      type = EntityType.fromString(getSign().getLine(3));
    }

    try {
      for (Entity e : LocationUtil.getNearbyEntities(location, new Vector(3, 3, 3))) {
        if (e.isDead() || !e.isValid()) {
          continue;
        }
        if (!type.is(e)) {
          continue;
        }

        String[] split = RegexUtil.COLON_PATTERN.split(getSign().getLine(2));
        double x = Double.parseDouble(split[0]);
        double y = Double.parseDouble(split[1]);
        double z = Double.parseDouble(split[2]);

        e.setVelocity(new org.bukkit.util.Vector(x, y, z).add(e.getVelocity()));

        resultBoolean = true;
      }
    } catch (Exception ignored) {
    }

    return resultBoolean;
  }
コード例 #2
0
ファイル: Chair.java プロジェクト: Energy0124/craftbook
  public void addChair(Player player, Block block) {

    if (disabled) return;
    try {
      PacketContainer entitymeta = ProtocolLibrary.getProtocolManager().createPacket(40);
      entitymeta.getSpecificModifier(int.class).write(0, player.getEntityId());
      WrappedDataWatcher watcher = new WrappedDataWatcher();
      watcher.setObject(0, (byte) 4);
      entitymeta.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());
      for (Player play : plugin.getServer().getOnlinePlayers()) {
        if (play.getWorld().equals(player.getPlayer().getWorld())) {
          try {
            ProtocolLibrary.getProtocolManager().sendServerPacket(play, entitymeta);
          } catch (InvocationTargetException e) {
            BukkitUtil.printStacktrace(e);
          }
        }
      }
    } catch (Error e) {
      Bukkit.getLogger().severe("Chairs do not work without ProtocolLib!");
      disabled = true;
      return;
    }
    if (chairs.containsKey(player.getName())) return;
    plugin.wrapPlayer(player).print(ChatColor.YELLOW + "You are now sitting.");
    chairs.put(player.getName(), block);
  }
コード例 #3
0
ファイル: CartLift.java プロジェクト: ScoreUnder/craftbook
  @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()));
  }
コード例 #4
0
ファイル: ParticleEffect.java プロジェクト: wizjany/craftbook
  public void doEffect() {

    try {
      if (effectID == 0) return;
      if (effectID == 2001 && BlockType.fromID(effectData) == null) return;
      Block b = SignUtil.getBackBlock(BukkitUtil.toSign(getSign()).getBlock());
      for (int i = 0; i < times; i++) {
        b.getWorld()
            .playEffect(b.getLocation().add(offset), Effect.getById(effectID), effectData, 50);
      }
    } catch (Exception ignored) {
    }
  }
コード例 #5
0
  public boolean collect() {

    boolean collected = false;

    for (Entity entity : LocationUtil.getNearbyEntities(centre, radius)) {
      if (entity.isValid() && entity instanceof Item) {
        if (LocationUtil.isWithinRadius(centre, entity.getLocation(), radius)) {

          stackCheck:
          {
            ItemStack stack = ((Item) entity).getItemStack();

            if (!ItemUtil.isStackValid(stack)) return false;

            for (ItemStack filter : filters) {

              if (!ItemUtil.isStackValid(filter)) continue;

              if (include && !ItemUtil.areItemsIdentical(filter, stack)) break stackCheck;
              else if (!include && ItemUtil.areItemsIdentical(filter, stack)) break stackCheck;
            }

            BlockFace back = SignUtil.getBack(BukkitUtil.toSign(getSign()).getBlock());
            Block pipe = getBackBlock().getRelative(back);

            Pipes pipes = Pipes.Factory.setupPipes(pipe, getBackBlock(), stack);

            if (pipes != null && pipes.getItems().isEmpty()) return true;

            // Add the items to a container, and destroy them.
            List<ItemStack> leftovers =
                InventoryUtil.addItemsToInventory((InventoryHolder) chest.getState(), stack);
            if (leftovers.isEmpty()) {
              entity.remove();
              return true;
            } else {
              if (ItemUtil.areItemsIdentical(leftovers.get(0), stack)
                  && leftovers.get(0).getAmount() != stack.getAmount()) {
                ((Item) entity).setItemStack(leftovers.get(0));
                return true;
              }
            }
          }
        }
      }
    }

    return collected;
  }
コード例 #6
0
  @Override
  public void load() {

    if (getLine(3).contains(":")) {
      type = Type.getFromChar(getLine(3).replace("!", "").trim().toCharArray()[0]);
    }
    if (type == null) type = Type.PLAYER;

    invertOutput = getLine(3).contains("!");

    nameLine =
        getLine(3).replace("g:", "").replace("p:", "").replace("n:", "").replace("!", "").trim();

    area = SearchArea.createArea(BukkitUtil.toSign(getSign()).getBlock(), getLine(2));
  }
コード例 #7
0
  @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!");
  }
コード例 #8
0
ファイル: Chair.java プロジェクト: Energy0124/craftbook
  public void removeChair(Player player) {

    if (disabled) return;
    PacketContainer entitymeta = ProtocolLibrary.getProtocolManager().createPacket(40);
    entitymeta.getSpecificModifier(int.class).write(0, player.getEntityId());
    WrappedDataWatcher watcher = new WrappedDataWatcher();
    watcher.setObject(0, (byte) 0);
    entitymeta.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());

    for (Player play : plugin.getServer().getOnlinePlayers()) {
      if (play.getWorld().equals(player.getPlayer().getWorld())) {
        try {
          ProtocolLibrary.getProtocolManager().sendServerPacket(play, entitymeta);
        } catch (InvocationTargetException e) {
          BukkitUtil.printStacktrace(e);
        }
      }
    }
    plugin.wrapPlayer(player).print(ChatColor.YELLOW + "You are no longer sitting.");
    chairs.remove(player.getName());
  }
コード例 #9
0
ファイル: EntitySensor.java プロジェクト: MCRUS/craftbook
  @Override
  public void load() {

    // lets get the types to detect first
    types =
        EntityType.getDetected(
            getLine(3)
                .split("<")[0]
                .trim()
                .split("<=")[0]
                .trim()
                .split(">=")[0]
                .trim()
                .split("==")[0]
                .trim()
                .split(">")[0]
                .trim());

    if (getLine(3).contains(">=")) minMode = 0;
    else if (getLine(3).contains("==")) minMode = 1;
    else if (getLine(3).contains(">")) minMode = 2;
    else if (getLine(3).contains("<=")) minMode = 3;
    else if (getLine(3).contains("<")) minMode = 4;
    else minMode = 0;

    try {
      if (minMode == 0) minimum = Short.parseShort(getLine(3).split(">=")[1].trim());
      else if (minMode == 1) minimum = Short.parseShort(getLine(3).split("==")[1].trim());
      else if (minMode == 2) minimum = Short.parseShort(getLine(3).split(">")[1].trim());
      else if (minMode == 3) minimum = Short.parseShort(getLine(3).split("<=")[1].trim());
      else if (minMode == 4) minimum = Short.parseShort(getLine(3).split("<")[1].trim());
    } catch (Exception e) {
      minimum = 1;
    }

    area = SearchArea.createArea(BukkitUtil.toSign(getSign()).getBlock(), getLine(2));
  }
コード例 #10
0
  public void terraform(boolean overrideChance) {

    for (int x = -radius.getBlockX() + 1; x < radius.getBlockX(); x++) {
      for (int y = -radius.getBlockY() + 1; y < radius.getBlockY(); y++) {
        for (int z = -radius.getBlockZ() + 1; z < radius.getBlockZ(); z++) {
          if (overrideChance || CraftBookPlugin.inst().getRandom().nextInt(40) == 0) {
            int rx = location.getX() - x;
            int ry = location.getY() - y;
            int rz = location.getZ() - z;
            Block b = BukkitUtil.toSign(getSign()).getWorld().getBlockAt(rx, ry, rz);
            if (b.getTypeId() == BlockID.CROPS && b.getData() < 0x7) {
              if (consumeBonemeal()) {
                b.setData((byte) (b.getData() + 0x1));
              }
              return;
            }
            if ((b.getTypeId() == BlockID.CROPS
                    || b.getTypeId() == BlockID.CARROTS
                    || b.getTypeId() == BlockID.POTATOES
                    || b.getTypeId() == BlockID.MELON_STEM
                    || b.getTypeId() == BlockID.PUMPKIN_STEM)
                && b.getData() < 0x7) {
              if (consumeBonemeal()) {
                byte add = (byte) CraftBookPlugin.inst().getRandom().nextInt(3);
                if (b.getData() + add > 0x7) b.setData((byte) 0x7);
                else b.setData((byte) (b.getData() + add));
              }
              return;
            }
            if (b.getTypeId() == BlockID.COCOA_PLANT
                && ((b.getData() & 0x8) != 0x8 || (b.getData() & 0xC) != 0xC)) {
              if (consumeBonemeal()) {
                if (CraftBookPlugin.inst().getRandom().nextInt(30) == 0)
                  b.setData((byte) (b.getData() | 0xC));
                else b.setData((byte) (b.getData() | 0x8));
              }
              return;
            }
            if (b.getTypeId() == BlockID.NETHER_WART && b.getData() < 0x3) {
              if (consumeBonemeal()) {
                b.setData((byte) (b.getData() + 0x1));
              }
              return;
            }
            if (b.getTypeId() == BlockID.SAPLING) {
              if (consumeBonemeal()) {
                if (!growTree(b, CraftBookPlugin.inst().getRandom())) refundBonemeal();
                else return;
              }
            }
            if (b.getTypeId() == BlockID.BROWN_MUSHROOM || b.getTypeId() == BlockID.RED_MUSHROOM) {
              if (consumeBonemeal()) {
                if (b.getTypeId() == BlockID.BROWN_MUSHROOM) {
                  b.setTypeId(0);
                  if (!b.getWorld().generateTree(b.getLocation(), TreeType.BROWN_MUSHROOM)) {
                    b.setTypeId(BlockID.BROWN_MUSHROOM);
                    refundBonemeal();
                  } else return;
                }
                if (b.getTypeId() == BlockID.RED_MUSHROOM) {
                  b.setTypeId(0);
                  if (!b.getWorld().generateTree(b.getLocation(), TreeType.RED_MUSHROOM)) {
                    b.setTypeId(BlockID.RED_MUSHROOM);
                    refundBonemeal();
                  } else return;
                }
              }
            }
            if ((b.getTypeId() == BlockID.REED || b.getTypeId() == BlockID.CACTUS)
                && b.getData() < 0x15
                && b.getRelative(0, 1, 0).getTypeId() == 0) {
              if (consumeBonemeal()) {
                b.getRelative(0, 1, 0).setTypeId(b.getTypeId());
              }
              return;
            }
            if (b.getTypeId() == BlockID.DIRT && b.getRelative(0, 1, 0).getTypeId() == 0) {
              if (consumeBonemeal()) {
                b.setTypeId(
                    b.getBiome() == Biome.MUSHROOM_ISLAND || b.getBiome() == Biome.MUSHROOM_SHORE
                        ? BlockID.MYCELIUM
                        : BlockID.GRASS);
              }
              return;
            }
            if (b.getTypeId() == BlockID.GRASS
                && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) {
              if (consumeBonemeal()) {
                int t = CraftBookPlugin.inst().getRandom().nextInt(7);
                if (t == 0) {
                  b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 1, true);
                } else if (t == 1) {
                  b.getRelative(0, 1, 0).setTypeId(BlockID.YELLOW_FLOWER);
                } else if (t == 2) {
                  b.getRelative(0, 1, 0).setTypeId(BlockID.RED_FLOWER);
                } else if (t == 3) {
                  b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 2, true);
                } else {
                  b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 1, true);
                }
              }
              return;
            }
            if (b.getTypeId() == BlockID.SAND
                && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) {
              if (consumeBonemeal()) {
                b.getRelative(0, 1, 0).setTypeIdAndData(BlockID.LONG_GRASS, (byte) 0, true);
              }
              return;
            }
            if (b.getTypeId() == BlockID.VINE
                && b.getRelative(0, -1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) {
              if (consumeBonemeal()) {
                b.getRelative(0, -1, 0).setTypeIdAndData(BlockID.VINE, b.getData(), true);
              }
              return;
            }
            if (b.getTypeId() == BlockID.STATIONARY_WATER
                && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(30) == 0) {
              if (consumeBonemeal()) {
                b.getRelative(0, 1, 0).setTypeId(BlockID.LILY_PAD);
              }
              return;
            }
            if (b.getTypeId() == BlockID.MYCELIUM
                && b.getRelative(0, 1, 0).getTypeId() == BlockID.AIR
                && CraftBookPlugin.inst().getRandom().nextInt(15) == 0) {
              if (consumeBonemeal()) {
                int t = CraftBookPlugin.inst().getRandom().nextInt(2);
                if (t == 0) {
                  b.getRelative(0, 1, 0).setTypeId(BlockID.RED_MUSHROOM);
                } else if (t == 1) {
                  b.getRelative(0, 1, 0).setTypeId(BlockID.BROWN_MUSHROOM);
                }
              }
              return;
            }
          }
        }
      }
    }
  }
コード例 #11
0
ファイル: EntitySensor.java プロジェクト: MCRUS/craftbook
    @Override
    public void verify(ChangedSign sign) throws ICVerificationException {

      if (!SearchArea.isValidArea(BukkitUtil.toSign(sign).getBlock(), sign.getLine(2)))
        throw new ICVerificationException("Invalid SearchArea on 3rd line!");
    }
コード例 #12
0
  @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;
        }
      }
    }
  }
コード例 #13
0
  @Command(
      aliases = {"save"},
      desc = "Saves the selected area",
      usage = "[-n namespace ] <id>",
      flags = "n:",
      min = 1)
  public void saveArea(CommandContext context, CommandSender sender) throws CommandException {

    if (!(sender instanceof Player)) return;
    LocalPlayer player = plugin.wrapPlayer((Player) sender);

    String id;
    String namespace = player.getName();
    boolean personal = true;

    if (context.hasFlag('n')
        && player.hasPermission("craftbook.mech.area.save." + context.getFlag('n'))) {
      namespace = context.getFlag('n');
      personal = false;
    } else if (!player.hasPermission("craftbook.mech.area.save.self"))
      throw new CommandPermissionsException();

    if (plugin.getConfiguration().areaShortenNames && namespace.length() > 14)
      namespace = namespace.substring(0, 14);

    if (!CopyManager.isValidNamespace(namespace))
      throw new CommandException("Invalid namespace. Needs to be between 1 and 14 letters long.");

    if (personal) {
      namespace = "~" + namespace;
    }

    id = context.getString(0);

    if (!CopyManager.isValidName(id))
      throw new CommandException("Invalid area name. Needs to be between 1 and 13 letters long.");

    try {
      WorldEditPlugin worldEdit = CraftBookPlugin.plugins.getWorldEdit();

      World world = ((Player) sender).getWorld();
      Selection sel = worldEdit.getSelection((Player) sender);
      if (sel == null) {
        sender.sendMessage(ChatColor.RED + "You have not made a selection!");
        return;
      }
      Vector min = BukkitUtil.toVector(sel.getMinimumPoint());
      Vector max = BukkitUtil.toVector(sel.getMaximumPoint());
      Vector size = max.subtract(min).add(1, 1, 1);

      // Check maximum size
      if (config.areaMaxAreaSize != -1
          && size.getBlockX() * size.getBlockY() * size.getBlockZ() > config.areaMaxAreaSize) {
        throw new CommandException(
            "Area is larger than allowed " + config.areaMaxAreaSize + " blocks.");
      }

      // Check to make sure that a user doesn't have too many toggle
      // areas (to prevent flooding the server with files)
      if (config.areaMaxAreaPerUser >= 0 && !namespace.equals("global")) {
        int count = copyManager.meetsQuota(world, namespace, id, config.areaMaxAreaPerUser);

        if (count > -1) {
          throw new CommandException(
              "You are limited to "
                  + config.areaMaxAreaPerUser
                  + " toggle area(s). "
                  + "You have "
                  + count
                  + " areas.");
        }
      }

      // Copy
      CuboidCopy copy;

      if (config.areaUseSchematics) {
        copy = new MCEditCuboidCopy(min, size, world);
      } else {
        copy = new FlatCuboidCopy(min, size, world);
      }

      copy.copy();

      plugin
          .getServer()
          .getLogger()
          .info(
              player.getName()
                  + " saving toggle area with folder '"
                  + namespace
                  + "' and ID '"
                  + id
                  + "'.");

      // Save
      try {
        CopyManager.getInstance().save(world, namespace, id.toLowerCase(Locale.ENGLISH), copy);
        player.print("Area saved as '" + id + "' under the '" + namespace + "' namespace.");
      } catch (IOException e) {
        player.printError("Could not save area: " + e.getMessage());
      } catch (DataException e) {
        player.print(e.getMessage());
      }
    } catch (NoClassDefFoundError e) {
      throw new CommandException(
          "WorldEdit.jar does not exist in plugins/, or is outdated. (Or you are using an outdated version of CraftBook)");
    }
  }
コード例 #14
0
ファイル: SetBridge.java プロジェクト: MCRUS/craftbook
  @Override
  public void load() {

    center = getBackBlock();
    faceing = SignUtil.getFacing(BukkitUtil.toSign(getSign()).getBlock());
    String line = getSign().getLine(2);
    if (!line.isEmpty()) {
      try {
        String[] split = RegexUtil.MINUS_PATTERN.split(line);
        // parse the material data
        if (split.length > 0) {
          try {
            // parse the data that gets set when the block is toggled off
            String[] strings = RegexUtil.COLON_PATTERN.split(split[1]);
            offMaterial = Integer.parseInt(strings[0]);
            if (strings.length > 0) {
              offData = Integer.parseInt(strings[1]);
            }
          } catch (NumberFormatException e) {
            offMaterial = 0;
            offData = 0;
          } catch (ArrayIndexOutOfBoundsException e) {
            offData = 0;
          }
        }
        // parse the material and data for toggle on
        String[] strings = RegexUtil.COLON_PATTERN.split(split[0]);
        onMaterial = Integer.parseInt(strings[0]);
        if (strings.length > 0) {
          onData = Integer.parseInt(strings[1]);
        }
      } catch (NumberFormatException e) {
        onMaterial = 1;
        onData = 0;
      } catch (ArrayIndexOutOfBoundsException e) {
        onData = 0;
      }
    }
    // parse the coordinates
    line = getSign().getLine(3);
    if (!line.trim().isEmpty()) {
      boolean relativeOffset = !line.contains("!");
      if (!relativeOffset) {
        line = line.trim().replace("!", "");
      }
      String[] split = RegexUtil.COLON_PATTERN.split(line);
      try {
        // parse the offset
        String[] offsetSplit = RegexUtil.COMMA_PATTERN.split(split[0]);
        offsetX = Integer.parseInt(offsetSplit[0]);
        offsetY = Integer.parseInt(offsetSplit[1]);
        offsetZ = Integer.parseInt(offsetSplit[2]);
      } catch (NumberFormatException e) {
        // ignore and use defaults
      } catch (IndexOutOfBoundsException e) {
        // ignore and use defaults
      }
      try {
        // parse the size of the door
        String[] sizeSplit = RegexUtil.COMMA_PATTERN.split(split[1]);
        width = Integer.parseInt(sizeSplit[0]);
        depth = Integer.parseInt(sizeSplit[1]);
      } catch (NumberFormatException e) {
        width = 1;
        depth = 1;
      } catch (ArrayIndexOutOfBoundsException e) {
        depth = 1;
      }
      if (relativeOffset) {
        center = LocationUtil.getRelativeOffset(getSign(), offsetX, offsetY, offsetZ);
      } else {
        center = LocationUtil.getOffset(center, offsetX, offsetY, offsetZ);
      }
    } else {
      center = center.getRelative(BlockFace.UP);
    }
  }