コード例 #1
0
 private static void ReadFile(File file, PluginDescriptionFile desc, Setting[] config) {
   try {
     for (int i = 0; i < config.length; i++) {
       String value =
           MinecartManiaFlatFile.getValueFromSetting(
               file, config[i].getName(), config[i].getValue().toString());
       // Attempt to parse the value as boolean
       if (value.contains("true")) {
         MinecartManiaWorld.setConfigurationValue(config[i].getName(), Boolean.TRUE);
       } else if (value.contains("false")) {
         MinecartManiaWorld.setConfigurationValue(config[i].getName(), Boolean.FALSE);
       }
       // Attempt to parse the value as a double or integer
       else if (!StringUtils.getNumber(value).isEmpty()) {
         Double d = Double.valueOf(StringUtils.getNumber(value));
         if (d.intValue() == d) {
           MinecartManiaWorld.setConfigurationValue(
               config[i].getName(), new Integer(d.intValue()));
         } else {
           MinecartManiaWorld.setConfigurationValue(config[i].getName(), d);
         }
       }
       // Fallback on string
       else {
         MinecartManiaWorld.setConfigurationValue(config[i].getName(), value);
       }
     }
   } catch (Exception exception) {
     MinecartManiaCore.log.severe("Failed to read " + desc.getName() + " settings!");
     exception.printStackTrace();
   }
 }
コード例 #2
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);
   }
 }
コード例 #3
0
  /**
   * Merges lines on a sign into a single line for processing, when the direction on the lines
   * match. Needed for support of the '!' character.
   */
  public static ArrayList<String> getItemLines(Sign sign) {
    HashMap<CompassDirection, String> directions = new HashMap<CompassDirection, String>(5);
    ArrayList<String> lines = new ArrayList<String>(3);
    for (int line = 1; line < 4; line++) {
      String text = StringUtils.removeBrackets(sign.getLine(line)).trim();
      if (!text.isEmpty() && !isFurnaceFuelLine(text) && !isFurnaceSmeltLine(text)) {
        CompassDirection direction = ItemUtils.getLineItemDirection(text);
        if (!directions.containsKey(direction)) {
          directions.put(direction, text);
        } else {
          String format = text;
          if (direction != CompassDirection.NO_DIRECTION) {
            format = format.substring(2);
          }
          directions.put(direction, directions.get(direction) + ":" + format);
        }
      }
    }

    MinecartManiaLogger.getInstance().debug("Merged Item Strings");
    Iterator<Entry<CompassDirection, String>> i = directions.entrySet().iterator();
    while (i.hasNext()) {
      Entry<CompassDirection, String> entry = i.next();
      lines.add(entry.getValue());
      MinecartManiaLogger.getInstance().debug("Item String: " + entry.getValue());
    }
    return lines;
  }
コード例 #4
0
  public SetMaxSpeedAction(Sign sign) {

    for (String line : sign.getLines()) {
      if (line.toLowerCase().contains("max speed")) {
        String[] split = line.split(":");
        if (split.length != 2) continue;
        double percent = Double.parseDouble(StringUtils.getNumber(split[1]));
        percent = Math.min(percent, MinecartManiaConfiguration.getMaximumMinecartSpeedPercent());
        this.percent = (int) percent;
        sign.addBrackets();
        break;
      }
    }
  }
コード例 #5
0
  private static void readFile(PluginDescriptionFile desc, Setting config[]) {

    File directory = new File(MinecartManiaCore.dataDirectory);
    if (!directory.exists()) directory.mkdir();
    String input = MinecartManiaCore.dataDirectory + File.separator;
    input += StringUtils.removeWhitespace(desc.getName());
    input += "Settings.txt";
    File options = new File(input);
    if (!options.exists() || invalidFile(options, config)) {
      WriteFile(options, desc, config);
    }
    /*else if (invalidFile(options)) {
    	updateFile(options);
    }*/
    ReadFile(options, desc, config);
  }
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    @SuppressWarnings("unused")
    int page;
    if (args.length == 0) {
      page = 1;
    } else {
      try {
        page = Integer.valueOf(StringUtils.getNumber(args[0]));
      } catch (NumberFormatException e) {
        page = 1;
      }
    }

    return false;
  }
コード例 #7
0
 @Override
 public String getName() {
   return StringUtils.removeWhitespace(setting.toLowerCase()) + "sign";
 }
コード例 #8
0
 private static void bracketizeSign(Sign sign) {
   for (int line = 0; line < 4; line++) {
     if (!sign.getLine(line).trim().isEmpty())
       sign.setLine(line, StringUtils.addBrackets(StringUtils.removeBrackets(sign.getLine(line))));
   }
 }
コード例 #9
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;
          }
        }
      }
    }
  }