コード例 #1
0
  protected static boolean processStationCommand(MinecartManiaMinecart minecart, String str) {
    boolean valid = false;

    if (!str.toLowerCase().contains("st-")) {
      return false;
    }
    String[] val =
        str.toLowerCase()
            .split(
                ":"); // Will doing a toLowerCase here mess up regular expressions?  Probably not
                      // since we lower case the station name anyway.
    String[] keys =
        val[0].split(
            "-| ?: ?",
            2); // Split the st- from the station name. the ",2" limits it to the first "-" followed
                // by zero or one non-capturing spaces.
    // The ",2" is needed because regular expressions can have a "-" in them. example "st-[g-z].*"
    // Without the limit, we would have the following array in keys: "st", "[g", "z].*" and then
    // only work with the "[g" portion which is wrong.
    String st = keys[1]; // Get the station name/simple pattern/regular expression
    String station =
        MinecartManiaWorld.getMinecartManiaPlayer(minecart.getPlayerPassenger())
            .getLastStation()
            .toLowerCase();
    int parseSetting =
        (Integer) MinecartManiaWorld.getConfigurationValue("StationSignParsingMethod");
    MinecartManiaLogger.getInstance()
        .debug("Given Sign Line: " + str + " Given Station setting: " + station);
    switch (parseSetting) {
      case 0: // default with no pattern matching
        valid = station.equalsIgnoreCase(st);
        break;
      case 1: // simple pattern matching
        st =
            st.replace("\\", "\\\\") // escapes backslashes in case people use them in station names
                .replace(".", "\\.") // escapes period
                .replace("*", ".*") // converts *
                .replace("?", ".") // converts ?
                .replace("#", "\\d") // converts #
                .replace(
                    "@",
                    "[a-zA-Z]"); // converts @  NOTE:[A-Z] is probably not needed here since
                                 // everything is lower case anyway, but left for completeness.
      case 2: // full regex //note the lack of break before this, case 1 comes down here after
              // converting
        valid = station.matches(st);
        break;
    }
    if (valid
        && MinecartManiaWorld.getMinecartManiaPlayer(minecart.getPlayerPassenger())
                .getDataValue("Reset Station Data")
            == null) {
      if (!StationUtil.isStationCommandNeverResets()) {
        MinecartManiaWorld.getMinecartManiaPlayer(minecart.getPlayerPassenger()).setLastStation("");
      }
    }
    return valid;
  }
コード例 #2
0
  public static boolean doMinecartCollection(final MinecartManiaMinecart minecart) {
    if (minecart.getBlockTypeAhead() != null) {
      if (minecart.getBlockTypeAhead().getType().getId() == Material.CHEST.getId()) {
        final MinecartManiaChest chest =
            MinecartManiaWorld.getMinecartManiaChest(
                (Chest) minecart.getBlockTypeAhead().getState());

        if (SignCommands.isNoCollection(chest)) return false;

        if (minecart instanceof MinecartManiaStorageCart) {
          final MinecartManiaStorageCart storageCart = (MinecartManiaStorageCart) minecart;
          boolean failed = false;
          for (final ItemStack item : storageCart.getInventory().getContents()) {
            if (!chest.addItem(item)) {
              failed = true;
              break;
            }
          }
          if (!failed) {
            storageCart.getInventory().clear();
          }
        }
        if (chest.addItem(minecart.getType().getId())) {

          minecart.kill(false);
          return true;
        }
      }
    }
    return false;
  }
コード例 #3
0
 public static boolean doCollectParallel(final MinecartManiaMinecart minecart) {
   final ArrayList<Block> blockList = minecart.getParallelBlocks();
   for (final Block block : blockList) {
     if (block.getState() instanceof Chest) {
       final MinecartManiaChest chest =
           MinecartManiaWorld.getMinecartManiaChest((Chest) block.getState());
       final ArrayList<Sign> signList =
           SignUtils.getAdjacentMinecartManiaSignList(chest.getLocation(), 1);
       for (final Sign sign : signList) {
         for (int i = 0; i < sign.getNumLines(); i++) {
           if (sign.getLine(i).toLowerCase().contains("parallel")) {
             sign.setLine(i, "[Parallel]");
             if (!minecart.isMovingAway(block.getLocation())) {
               if (chest.addItem(minecart.getType().getId())) {
                 minecart.kill(false);
                 return true;
               }
             }
           }
         }
       }
     }
   }
   return false;
 }
コード例 #4
0
 public void onMinecartMeetConditionEvent(MinecartMeetsConditionEvent event) {
   if (event.isMeetCondition()) {
     return;
   }
   Sign sign = event.getSign();
   MinecartManiaMinecart minecart = event.getMinecart();
   MinecartManiaPlayer player = null;
   Object old = null;
   if (minecart.hasPlayerPassenger()) {
     player = MinecartManiaWorld.getMinecartManiaPlayer(minecart.getPlayerPassenger());
     old = player.getDataValue("Reset Station Data");
     player.setDataValue("Reset Station Data", true);
   }
   loop:
   for (int i = 0; i < sign.getNumLines(); i++) {
     String line = StringUtils.removeBrackets(sign.getLine(i).trim());
     for (StationCondition e : StationCondition.values()) {
       if (e.result(minecart, line)) {
         event.setMeetCondition(true);
         break loop;
       }
     }
   }
   if (player != null) {
     player.setDataValue("Reset Station Data", old);
   }
 }
コード例 #5
0
 public static MinecartManiaInventory getMinecartManiaInventory(Block block) {
   MinecartManiaInventory inventory = null;
   if (block.getState() instanceof Chest) {
     inventory = MinecartManiaWorld.getMinecartManiaChest((Chest) block.getState());
     // check for double chest
     if (inventory != null && ((MinecartManiaChest) inventory).getNeighborChest() != null) {
       inventory =
           new MinecartManiaDoubleChest(
               (MinecartManiaChest) inventory,
               ((MinecartManiaChest) inventory).getNeighborChest());
     }
   } else if (block.getState() instanceof Dispenser) {
     inventory = MinecartManiaWorld.getMinecartManiaDispenser((Dispenser) block.getState());
   } else if (block.getState() instanceof Furnace) {
     inventory = MinecartManiaWorld.getMinecartManiaFurnace((Furnace) block.getState());
   }
   return inventory;
 }
コード例 #6
0
  public void onMinecartIntersectionEvent(MinecartIntersectionEvent event) {
    MinecartManiaMinecart minecart = event.getMinecart();

    if (event.isActionTaken()) {
      return;
    }

    if (ControlBlockList.isValidStationBlock(minecart)) {
      SignCommands.processStation(event);
    }

    if (event.isActionTaken()) {
      return;
    }

    if (StationUtil.shouldPromptUser(minecart)) {

      minecart.setDataValue("preintersection velocity", minecart.minecart.getVelocity().clone());
      minecart.stopCart();
      Player passenger = minecart.getPlayerPassenger();
      // set the track straight
      int data =
          DirectionUtils.getMinetrackRailDataForDirection(
              minecart.getDirection(), minecart.getDirection());
      Block oldBlock =
          MinecartManiaWorld.getBlockAt(
              minecart.minecart.getWorld(), minecart.getX(), minecart.getY(), minecart.getZ());
      ArrayList<Integer> blockData = new ArrayList<Integer>();
      blockData.add(new Integer(oldBlock.getX()));
      blockData.add(new Integer(oldBlock.getY()));
      blockData.add(new Integer(oldBlock.getZ()));
      blockData.add(new Integer(oldBlock.getData()));
      minecart.setDataValue("old rail data", blockData);
      if (data != -1) {
        MinecartManiaWorld.setBlockData(
            minecart.minecart.getWorld(), minecart.getX(), minecart.getY(), minecart.getZ(), data);
      }
      passenger.sendMessage(LocaleParser.getTextKey("StationsTapInDirection"));
    }
  }
コード例 #7
0
  public void onMinecartActionEvent(MinecartActionEvent event) {
    MinecartManiaMinecart minecart = event.getMinecart();

    if (!minecart.isAtIntersection()) {
      if (minecart.getDataValue("old rail data") != null) {
        @SuppressWarnings("unchecked")
        ArrayList<Integer> blockData = (ArrayList<Integer>) minecart.getDataValue("old rail data");
        MinecartManiaWorld.setBlockData(
            minecart.minecart.getWorld(),
            blockData.get(0),
            blockData.get(1),
            blockData.get(2),
            blockData.get(3));
        minecart.setDataValue("old rail data", null);
      }
    }

    // stop moving, there is a queue ahead of us
    // TODO Fix this
    /*MinecartManiaMinecart minecartAhead = minecart.getMinecartAhead();
    while (true) {
    	if (minecartAhead == null) {
    		break;
    	}
    	if (minecartAhead.minecart.getEntityId() == minecart.minecart.getEntityId()) {
    		break;
    	}
    	if (minecartAhead.getMinecartAhead() == null) {
    		break;
    	}
    	if (minecartAhead.isMoving()) {
    		break;
    	}
    	minecartAhead = minecartAhead.getMinecartAhead();
    }
    if (minecartAhead != null) {
    	if (minecartAhead.isAtIntersection()) {
    		if (!minecartAhead.isMoving()) {
    			minecart.setDataValue("queued velocity", minecart.minecart.getVelocity().clone());
    			minecart.stopCart();
    			if (minecart.hasPlayerPassenger())
    				ChatUtils.sendMultilineMessage(minecart.getPlayerPassenger(), "You've entered a queue. Please be patient.", ChatColor.YELLOW.toString());
    		}
    	}
    }*/
  }
コード例 #8
0
 @Override
 public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
   Player player = (Player) sender;
   if (args.length < 1) {
     return false;
   }
   MinecartManiaPlayer mmp = MinecartManiaWorld.getMinecartManiaPlayer(player);
   String station = args[0];
   mmp.setLastStation(station);
   if (args.length > 1) {
     if (args[1].contains("s")) {
       mmp.setDataValue("Reset Station Data", Boolean.TRUE);
     }
   } else {
     mmp.setDataValue("Reset Station Data", null);
   }
   mmp.sendMessage(LocaleParser.getTextKey("AdminControlsStation", station));
   return true;
 }
コード例 #9
0
  public void onMinecartClickedEvent(MinecartClickedEvent event) {
    if (event.isActionTaken()) {
      return;
    }
    MinecartManiaMinecart minecart = event.getMinecart();
    if (StationUtil.isInQueue(minecart)) {
      event.setActionTaken(true);
      return;
    }
    CompassDirection facingDir =
        DirectionUtils.getDirectionFromMinecartRotation(
            (minecart.minecart.getPassenger().getLocation().getYaw() - 90.0F) % 360.0F);

    Vector velocity = (Vector) minecart.getDataValue("preintersection velocity");
    if (velocity == null) {
      return;
    }

    velocity = StationUtil.alterMotionFromDirection(facingDir, velocity);

    // responding to chat direction prompt
    if (minecart.isAtIntersection() && minecart.hasPlayerPassenger()) {
      if (StationUtil.isValidDirection(facingDir, minecart)) {
        int data =
            DirectionUtils.getMinetrackRailDataForDirection(facingDir, minecart.getDirection());
        if (data != -1) {
          MinecartManiaWorld.setBlockData(
              minecart.minecart.getWorld(),
              minecart.getX(),
              minecart.getY(),
              minecart.getZ(),
              data);
        }
        minecart.minecart.setVelocity(velocity);
        minecart.setDataValue("preintersection velocity", null);
      }
      event.setActionTaken(true);
    }
  }
コード例 #10
0
 public static boolean useOldDirections() {
   return (Boolean) MinecartManiaWorld.getConfigurationValue("UseOldDirections");
 }
コード例 #11
0
 public static int getMinecartMaximumRange() {
   return (Integer) MinecartManiaWorld.getConfigurationValue("MaximumRange");
 }
コード例 #12
0
 public static boolean isKeepMinecartsLoaded() {
   return (Boolean) MinecartManiaWorld.getConfigurationValue("KeepMinecartsLoaded");
 }
コード例 #13
0
 public static boolean isReturnMinecartToOwner() {
   return (Boolean) MinecartManiaWorld.getConfigurationValue("MinecartsReturnToOwner");
 }
コード例 #14
0
 public static boolean isMinecartsKillMobs() {
   return (Boolean) MinecartManiaWorld.getConfigurationValue("MinecartsKillMobs");
 }
コード例 #15
0
  public static void processStation(MinecartEvent event) {
    MinecartManiaMinecart minecart = event.getMinecart();

    ArrayList<Sign> signList = SignUtils.getAdjacentSignList(minecart, 2);
    for (Sign sign : signList) {
      convertCraftBookSorter(sign);
      for (int k = 0; k < 4; k++) {
        // Setup initial data
        String str = sign.getLine(k);
        String newLine = str;
        String val[] = str.split(":");
        if (val.length != 2) {
          continue;
        }
        // Strip header and ending characters
        val[0] = StringUtils.removeBrackets(val[0]);
        val[1] = StringUtils.removeBrackets(val[1]);
        // Strip whitespace
        val[0] = val[0].trim();
        val[1] = val[1].trim();
        boolean valid = false;
        // end of data setup

        for (StationCondition e : StationCondition.values()) {
          if (e.result(minecart, val[0])) {
            valid = true;
            break;
          }
        }

        if (valid) {
          CompassDirection direction = CompassDirection.NO_DIRECTION;

          for (StationDirection e : StationDirection.values()) {
            direction = e.direction(minecart, val[1]);
            if (direction != CompassDirection.NO_DIRECTION) {
              break;
            }
          }

          // Special case - if we are at a launcher, set the launch speed as well
          // mze 2012-08-29: Remove it because it makes more problems than it solves...
          /*if (event instanceof MinecartLaunchedEvent && direction != null && direction != CompassDirection.NO_DIRECTION) {
          	minecart.setMotion(direction, 0.6D);
          	((MinecartLaunchedEvent)event).setLaunchSpeed(minecart.minecart.getVelocity());
          }*/

          // setup sign formatting
          newLine = StringUtils.removeBrackets(newLine);
          char[] ch = {' ', ':'};
          newLine = WordUtils.capitalize(newLine, ch);
          newLine = StringUtils.addBrackets(newLine);

          boolean handled = false;
          // Handle minecart destruction
          if (direction == null) {
            // vanish sign, minecart is just gone ;)
            if (val[1].equals("V") || val[1].toLowerCase().contains("vanish")) {
              minecart.kill(false);
            }

            minecart.kill();
            handled = true;
          } else if (MinecartUtils.validMinecartTrack(
              minecart.minecart.getWorld(),
              minecart.getX(),
              minecart.getY(),
              minecart.getZ(),
              2,
              direction)) {
            int data =
                DirectionUtils.getMinetrackRailDataForDirection(direction, minecart.getDirection());
            if (data != -1) {
              handled = true;

              // Force the game to remember the old data of the rail we are on, and reset it once we
              // are done
              Block oldBlock =
                  MinecartManiaWorld.getBlockAt(
                      minecart.minecart.getWorld(),
                      minecart.getX(),
                      minecart.getY(),
                      minecart.getZ());
              ArrayList<Integer> blockData = new ArrayList<Integer>();
              blockData.add(new Integer(oldBlock.getX()));
              blockData.add(new Integer(oldBlock.getY()));
              blockData.add(new Integer(oldBlock.getZ()));
              blockData.add(new Integer(oldBlock.getData()));
              minecart.setDataValue("old rail data", blockData);

              // change the track dirtion
              MinecartManiaWorld.setBlockData(
                  minecart.minecart.getWorld(),
                  minecart.getX(),
                  minecart.getY(),
                  minecart.getZ(),
                  data);
            } else if (DirectionUtils.getOppositeDirection(direction)
                .equals(minecart.getDirection())) {
              // format the sign
              minecart.reverse();
              handled = true;
            }
          }

          if (handled) {
            event.setActionTaken(true);
            // format the sign
            sign.setLine(k, newLine);
            sign.update(true);
            return;
          }
        }
      }
    }
  }
コード例 #16
0
 public static boolean isStackAllItems() {
   return (Boolean) MinecartManiaWorld.getConfigurationValue("StackAllItems");
 }
コード例 #17
0
 public static int getMinecartRangeY() {
   return (Integer) MinecartManiaWorld.getConfigurationValue("RangeY");
 }
コード例 #18
0
 public static boolean isLimitedSignRange() {
   return (Boolean) MinecartManiaWorld.getConfigurationValue("LimitedSignRange");
 }
コード例 #19
0
 public static boolean isDisappearOnDisconnect() {
   return (Boolean) MinecartManiaWorld.getConfigurationValue("DisappearOnDisconnect");
 }
コード例 #20
0
 public static int getMaximumMinecartSpeedPercent() {
   return (Integer) MinecartManiaWorld.getConfigurationValue("MaximumMinecartSpeedPercent");
 }
コード例 #21
0
 public static int getMinecartsClearRailsSetting() {
   return (Integer) MinecartManiaWorld.getConfigurationValue("MinecartsClearRails");
 }