Exemple #1
0
 /**
  * Try to send the cart to its return address
  *
  * @return true if success
  */
 private boolean tryReturnCart() {
   Address returnAddress = ReturnAddressFactory.getAddress(this.getInventory());
   if (returnAddress != null && returnAddress.isReturnable()) {
     (new BC7017(this.getBlock(), this.getVehicle())).trigger();
     return true;
   }
   return false;
 }
Exemple #2
0
  /**
   * Compute the direction to take
   *
   * @param IPaddress the destination address
   * @param sign the BC sign
   * @param RoutingTableWritable the routing table contained in the chest
   * @return the direction to destination, or to ring 0. If ring 0 does not exist, random direction
   */
  protected BlockFace SelectRoute(
      AddressRouted IPaddress, Address sign, RoutingTableWritable RoutingTable) {

    DirectionRegistry face;
    // same region : lookup destination track
    if (IPaddress != null
        && IPaddress.getRegion().getAmount() == sign.getRegion().getAmount()
        && IPaddress.getTTL() != 0) {
      int destination = this.destination.getTrack().getAmount();
      DirectionRegistry out = RoutingTable.getDirection(destination);
      if (out != null) {
        // trigger event
        SignPreRouteEvent event =
            new SignPreRouteEvent(this, this.getRoutingTable().getDirectlyConnected(out));
        Bukkit.getServer().getPluginManager().callEvent(event);
        return RoutingTable.getDirection(event.getTargetTrack()).getBlockFace();
      }
    }

    // If not in same region, or if TTL is 0, or the ring does not exist then we lookup track 0
    if ((face = RoutingTable.getDirection(0)) != null) return face.getBlockFace();

    // If everything has failed, then we randomize output direction
    return AbstractWanderer.getRandomBlockFace(RoutingTable, getCardinal().getOppositeFace());
  }
Exemple #3
0
  @Override
  public void doAction(Side to) {
    Address address = this.getSignAddress();

    // Keep track on the subring level we are in
    int mask = this.getNetmask();
    if (mask < 8) {
      Stack<Integer> end = this.getEnd();
      if (to.equals(Side.LEVER_ON) && (end.isEmpty() || mask > end.peek())) {
        end.push(mask);
        if (ByteCart.debug) ByteCart.log.info("ByteCart : pushing mask " + mask + " on stack");
      } else if (to.equals(Side.LEVER_OFF) && !end.isEmpty()) {
        if (ByteCart.debug)
          ByteCart.log.info("ByteCart : popping mask " + end.peek() + " from stack");

        end.pop();
      }
    }
    save();

    // if we are not in the good region, skip update
    if (getContent().getCurrent() != getContent().getRegion()) return;

    if (address.isValid() && this.getContent().isFullreset()) {
      if (this.getNetmask() == 8) {
        UpdaterClearStationEvent event = new UpdaterClearStationEvent(this, address);
        Bukkit.getServer().getPluginManager().callEvent(event);
      } else {
        UpdaterClearSubnetEvent event =
            new UpdaterClearSubnetEvent(this, address, 256 >> this.getNetmask());
        Bukkit.getServer().getPluginManager().callEvent(event);
      }
    } else {
      UpdaterSignInvalidateEvent event = new UpdaterSignInvalidateEvent(this);
      Bukkit.getServer().getPluginManager().callEvent(event);
      if (!this.getContent().isFullreset()) return;
    }
    address.remove();
    if (ByteCart.debug) ByteCart.log.info("ByteCart: removing address");
  }
Exemple #4
0
 /* (non-Javadoc)
  * @see com.github.catageek.ByteCart.Signs.BCRouter#getOriginTrack()
  */
 @Override
 public final int getOriginTrack() {
   return Sign.getTrack().getAmount();
 }
Exemple #5
0
  /**
   * bcticket command.
   *
   * <p>Usage: /bcticket destination [isTrain] OR /bcticket player destination [isTrain]
   *
   * @param sender
   * @param cmd
   * @param label
   * @param args
   * @return True on success of the command.
   */
  protected boolean bcticket(CommandSender sender, Command cmd, String label, String[] args) {
    Player player;
    Address destination;
    String addressString;
    boolean isTrain = false;

    if (!(sender instanceof Player)) {
      if (args.length < 2) {
        return false;
      }

      if (!AddressString.isResolvableAddressOrName(args[1])) {
        sender.sendMessage(
            ChatColor.DARK_GREEN
                + "[Bytecart] "
                + ChatColor.RED
                + ByteCart.myPlugin.getConfig().getString("Info.NoValidAddress"));
        return false;
      }

      player = Bukkit.getServer().getPlayer(args[0]);
      addressString = args[1];
      isTrain = (args.length == 3 && args[2].equalsIgnoreCase("train"));

      if (player == null) {
        sender.sendMessage(
            ChatColor.DARK_GREEN
                + "[Bytecart] "
                + ChatColor.RED
                + ByteCart.myPlugin.getConfig().getString("Info.FindPlayer")
                + args[0]
                + ".");
        return false;
      }
    } else {
      if (args.length < 1) {
        return false;
      }

      player = (Player) sender;
      addressString = args[0];
      isTrain = (args.length == 2 && args[1].equalsIgnoreCase("train"));
    }

    if (!AddressString.isResolvableAddressOrName(addressString)) {
      sender.sendMessage(
          ChatColor.DARK_GREEN
              + "[Bytecart] "
              + ChatColor.RED
              + ByteCart.myPlugin.getConfig().getString("Info.NoValidAddress"));
      return false;
    }

    destination = new AddressString(addressString);
    destination.setTrain(isTrain);

    (new BC7010(player.getLocation().getBlock(), player)).setAddress(destination, null);

    player.sendMessage(
        ChatColor.DARK_GREEN
            + "[Bytecart] "
            + ChatColor.YELLOW
            + ByteCart.myPlugin.getConfig().getString("Info.TicketCreated"));

    return true;
  }