Exemplo n.º 1
0
  BC8010(Block block, org.bukkit.entity.Vehicle vehicle)
      throws ClassNotFoundException, IOException {
    super(block, vehicle);
    this.IsTrackNumberProvider = true;
    From = this.getCardinal().getOppositeFace();
    // reading destination address of the cart
    destination = AddressFactory.getAddress(this.getInventory());
    // reading address written on BC8010 sign
    Sign = AddressFactory.getAddress(this.getBlock(), 3);
    // Center of the router, at sign level
    center =
        this.getBlock()
            .getRelative(this.getCardinal(), 6)
            .getRelative(MathUtil.clockwise(this.getCardinal()));

    BlockState blockstate;

    if ((blockstate = center.getRelative(BlockFace.UP, 5).getState()) instanceof InventoryHolder) {
      // Loading inventory of chest above router
      Inventory ChestInventory = ((InventoryHolder) blockstate).getInventory();

      // Converting inventory in routing table
      RoutingTable = RoutingTableFactory.getRoutingTable(ChestInventory);
    } else {
      RoutingTable = null;
    }
  }
Exemplo n.º 2
0
 public void run() {
   if ((new BC7011(
           player.getLocation().getBlock(),
           ((org.bukkit.entity.Vehicle) inventory.getHolder())))
       .setAddress(address, null, this.istrain)) {
     LogUtil.sendSuccess(
         player,
         ByteCart.myPlugin.getConfig().getString("Info.SetAddress") + " " + address);
     LogUtil.sendSuccess(
         player,
         ByteCart.myPlugin.getConfig().getString("Info.GetTTL")
             + AddressFactory.<AddressRouted>getAddress(inventory).getTTL());
   } else
     LogUtil.sendError(
         player, ByteCart.myPlugin.getConfig().getString("Error.SetAddress"));
 }
Exemplo n.º 3
0
  /* (non-Javadoc)
   * @see com.github.catageek.ByteCart.Signs.Triggable#trigger()
   */
  @Override
  public void trigger() throws ClassNotFoundException, IOException {

    CollisionAvoiderBuilder builder = new RouterCollisionAvoiderBuilder(this, center.getLocation());

    try {

      BlockFace direction, to;
      Router router =
          ByteCart.myPlugin.getCollisionAvoiderManager().<Router>getCollisionAvoider(builder);
      boolean isTrain = AbstractTriggeredSign.isTrain(destination);

      // Here begins the triggered action

      // is this an wanderer who needs special routing ? no then routing normally
      if (selectWanderer()) {

        // if this is a cart in a train
        if (this.wasTrain(this.getLocation())) {

          // leave a message to next cart that it is a train
          ByteCart.myPlugin.getIsTrainManager().getMap().reset(getLocation());
          // tell to router not to change position
          ByteCart.myPlugin
              .getCollisionAvoiderManager()
              .<Router>getCollisionAvoider(builder)
              .Book(isTrain);
          return;
        }

        if (destination != null) {
          // Time-to-live management

          // loading TTl of cart
          int ttl = destination.getTTL();

          // if ttl did not reach end of life ( = 0)
          if (ttl != 0) {

            destination.updateTTL(ttl - 1);
          }

          // if ttl was 1 (now 0), we try to return the cart to source station

          if (ttl == 1 && tryReturnCart())
            destination = AddressFactory.getAddress(this.getInventory());

          if (ByteCart.debug) ByteCart.log.info("ByteCart : TTL is " + destination.getTTL());

          // if this is the first car of a train
          // we keep it during 2 s
          if (isTrain) {
            this.setWasTrain(this.getLocation(), true);
          }

          destination.finalizeAddress();
        }

        direction = this.SelectRoute(destination, Sign, RoutingTable);

        // trigger event
        BlockFace bdest = router.WishToGo(From, direction, isTrain);
        int ring = this.getRoutingTable().getDirectlyConnected(new DirectionRegistry(bdest));
        SignPostRouteEvent event = new SignPostRouteEvent(this, ring);
        Bukkit.getServer().getPluginManager().callEvent(event);

        return;
      }

      // it's a wanderer, so let it choosing direction
      Wanderer wanderer = getWanderer();

      // routing normally
      to = router.WishToGo(From, wanderer.giveRouterDirection(), isTrain);

      if (WandererContentFactory.isWanderer(getInventory(), "Updater")) {
        int nextring = this.getRoutingTable().getDirectlyConnected(new DirectionRegistry(to));
        UpdaterPassRouterEvent event = new UpdaterPassRouterEvent(wanderer, to, nextring);
        Bukkit.getServer().getPluginManager().callEvent(event);
      }

      // here we perform routes update
      wanderer.doAction(to);

    } catch (ClassCastException e) {
      if (ByteCart.debug) ByteCart.log.info("ByteCart : " + e.toString());
      e.printStackTrace();

      // Not the good blocks to build the signs
      return;
    } catch (NullPointerException e) {
      if (ByteCart.debug) ByteCart.log.info("ByteCart : " + e.toString());

      e.printStackTrace();

      // there was no inventory in the cart
      return;
    }
  }