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; }
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); } }
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")); } }
public void onMinecartManiaMinecartDestroyedEvent(MinecartManiaMinecartDestroyedEvent event) { MinecartManiaMinecart minecart = event.getMinecart(); StationUtil.updateQueue(minecart); }
public void onMinecartMotionStartEvent(MinecartMotionStartEvent event) { MinecartManiaMinecart minecart = event.getMinecart(); if (minecart.isAtIntersection()) { StationUtil.updateQueue(minecart); } }