public void load(ConfigurationNode node) { this.keepSpawnInMemory = node.get("keepSpawnLoaded", this.keepSpawnInMemory); this.worldmode = WorldMode.get(node.get("environment", this.worldmode.getName())); this.chunkGeneratorName = node.get("chunkGenerator", String.class, this.chunkGeneratorName); if (LogicUtil.nullOrEmpty(this.chunkGeneratorName)) { this.chunkGeneratorName = null; } this.difficulty = node.get("difficulty", Difficulty.class, this.difficulty); this.gameMode = node.get("gamemode", GameMode.class, this.gameMode); this.clearInventory = node.get("clearInventory", this.clearInventory); String worldspawn = node.get("spawn.world", String.class); if (worldspawn != null) { double x = node.get("spawn.x", 0.0); double y = node.get("spawn.y", 64.0); double z = node.get("spawn.z", 0.0); double yaw = node.get("spawn.yaw", 0.0); double pitch = node.get("spawn.pitch", 0.0); this.spawnPoint = new Position(worldspawn, x, y, z, (float) yaw, (float) pitch); } this.holdWeather = node.get("holdWeather", this.holdWeather); this.formIce = node.get("formIce", this.formIce); this.formSnow = node.get("formSnow", this.formSnow); this.showRain = node.get("showRain", this.showRain); this.showSnow = node.get("showSnow", this.showSnow); this.pvp = node.get("pvp", this.pvp); this.forcedRespawn = node.get("forcedRespawn", this.forcedRespawn); this.allowHunger = node.get("hunger", this.allowHunger); this.rememberLastPlayerPosition = node.get("rememberlastplayerpos", this.rememberLastPlayerPosition); this.reloadWhenEmpty = node.get("reloadWhenEmpty", this.reloadWhenEmpty); for (String type : node.getList("deniedCreatures", String.class)) { type = type.toUpperCase(); if (type.equals("ANIMALS")) { this.spawnControl.setAnimals(true); } else if (type.equals("MONSTERS")) { this.spawnControl.setMonsters(true); } else { EntityType t = ParseUtil.parseEnum(EntityType.class, type, null); if (t != null) { this.spawnControl.deniedCreatures.add(t); } } } long time = node.get("lockedtime", Integer.MIN_VALUE); if (time != Integer.MIN_VALUE) { this.timeControl.setTime(time); this.timeControl.setLocking(true); } this.defaultNetherPortal = node.get("defaultNetherPortal", String.class, this.defaultNetherPortal); this.defaultEnderPortal = node.get("defaultEndPortal", String.class, this.defaultEnderPortal); if (node.contains("defaultPortal")) { // Compatibility mode this.defaultNetherPortal = node.get("defaultPortal", String.class, this.defaultNetherPortal); node.set("defaultPortal", null); } this.OPlist = node.getList("operators", String.class, this.OPlist); }
@Override public T convertSpecial(Object value, Class<?> valueType, T def) { String text = ConversionTypes.toString.convert(value); if (text != null) { return ParseUtil.parseEnum(getOutputType(), text, def); } else { return def; } }
/** * Writes this configuration to stream<br> * Note: Closes the stream when finished * * @param stream to write to */ public void saveToStream(OutputStream stream) throws IOException { // Get rid of newline characters in text - Bukkit bug prevents proper saving for (String key : this.getSource().getKeys(true)) { Object value = this.getSource().get(key); if (value instanceof String) { String text = (String) value; if (text.contains("\n")) { this.getSource().set(key, Arrays.asList(text.split("\n", -1))); } } } BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stream)); try { // Write the top header writeHeader(true, writer, this.getHeader(), 0); // Write other headers and the nodes IntHashMap<String> anchorData = new IntHashMap<String>(); int indent; int anchStart, anchEnd, anchId = -1, anchDepth = 0, anchIndent = 0; boolean wasAnchor; int refStart, refEnd, refId; StringBuilder refData = new StringBuilder(); NodeBuilder node = new NodeBuilder(this.getIndent()); for (String line : this.getSource().saveToString().split("\n", -1)) { line = StringUtil.colorToAmp(line); indent = StringUtil.getSuccessiveCharCount(line, ' '); line = line.substring(indent); wasAnchor = false; // ===== Logic start ===== // Get rid of the unneeded '-characters around certain common names if (line.equals("'*':")) { line = "*:"; } // Handle a node if (node.handle(line, indent)) { // Store old anchor data if (anchId >= 0 && node.getDepth() <= anchDepth) { anchorData.put(anchId, refData.toString()); refData.setLength(0); anchId = refId = -1; } // Saving a new node: Write the node header writeHeader(false, writer, this.getHeader(node.getPath()), indent); // Check if the value denotes a reference refStart = line.indexOf("*id", node.getName().length()); refEnd = line.indexOf(' ', refStart); if (refEnd == -1) { refEnd = line.length(); } if (refStart > 0 && refEnd > refStart) { // This is a reference pointer: get id refId = ParseUtil.parseInt(line.substring(refStart + 3, refEnd), -1); if (refId >= 0) { // Obtain the reference data String data = anchorData.get(refId); if (data != null) { // Replace the line with the new data line = StringUtil.trimEnd(line.substring(0, refStart)) + " " + data; } } } // Check if the value denotes a data anchor anchStart = line.indexOf("&id", node.getName().length()); anchEnd = line.indexOf(' ', anchStart); if (anchEnd == -1) { anchEnd = line.length(); } if (anchStart > 0 && anchEnd > anchStart) { // This is a reference node anchor: get id anchId = ParseUtil.parseInt(line.substring(anchStart + 3, anchEnd), -1); anchDepth = node.getDepth(); anchIndent = indent; if (anchId >= 0) { // Fix whitespace after anchor identifier anchEnd += StringUtil.getSuccessiveCharCount(line.substring(anchEnd), ' '); // Store the data of this anchor refData.append(line.substring(anchEnd)); // Remove the variable reference from saved data line = StringUtil.replace(line, anchStart, anchEnd, ""); } wasAnchor = true; } } if (!wasAnchor && anchId >= 0) { // Not an anchor: append anchor data refData .append('\n') .append(StringUtil.getFilledString(" ", indent - anchIndent)) .append(line); } // Write the data if (LogicUtil.containsChar('\n', line)) { for (String part : line.split("\n", -1)) { StreamUtil.writeIndent(writer, indent); writer.write(part); writer.newLine(); } } else { StreamUtil.writeIndent(writer, indent); writer.write(line); writer.newLine(); } } } finally { writer.close(); } }
@Override public boolean parseSet(String key, String arg) { if (key.equals("exitoffset")) { Vector vec = Util.parseVector(arg, null); if (vec != null) { for (CartProperties prop : this) { prop.exitOffset = vec; } } } else if (key.equals("exityaw")) { float yaw = ParseUtil.parseFloat(arg, 0.0f); for (CartProperties prop : this) { prop.exitYaw = yaw; } } else if (key.equals("exitpitch")) { float pitch = ParseUtil.parseFloat(arg, 0.0f); for (CartProperties prop : this) { prop.exitPitch = pitch; } } else if (LogicUtil.contains(key, "exitrot", "exitrotation")) { String[] angletext = Util.splitBySeparator(arg); float yaw = 0.0f; float pitch = 0.0f; if (angletext.length == 2) { yaw = ParseUtil.parseFloat(angletext[0], 0.0f); pitch = ParseUtil.parseFloat(angletext[1], 0.0f); } else if (angletext.length == 1) { yaw = ParseUtil.parseFloat(angletext[0], 0.0f); } for (CartProperties prop : this) { prop.exitYaw = yaw; prop.exitPitch = pitch; } } else if (key.equals("sound") || key.equals("minecartsound")) { this.soundEnabled = ParseUtil.parseBool(arg); } else if (key.equals("mobcollision")) { this.mobCollision = CollisionMode.parse(arg); } else if (key.equals("playercollision")) { this.playerCollision = CollisionMode.parse(arg); } else if (key.equals("misccollision")) { this.miscCollision = CollisionMode.parse(arg); } else if (key.equals("traincollision")) { this.trainCollision = CollisionMode.parse(arg); } else if (LogicUtil.contains(key, "collision", "collide")) { this.setColliding(ParseUtil.parseBool(arg)); } else if (LogicUtil.contains(key, "linking", "link")) { this.trainCollision = CollisionMode.fromLinking(ParseUtil.parseBool(arg)); } else if (LogicUtil.contains(key, "slow", "slowdown")) { this.setSlowingDown(ParseUtil.parseBool(arg)); } else if (LogicUtil.contains(key, "setdefault", "default")) { this.setDefault(arg); } else if (key.equals("pushmobs")) { this.mobCollision = CollisionMode.fromPushing(ParseUtil.parseBool(arg)); } else if (key.equals("pushplayers")) { this.playerCollision = CollisionMode.fromPushing(ParseUtil.parseBool(arg)); } else if (key.equals("pushmisc")) { this.miscCollision = CollisionMode.fromPushing(ParseUtil.parseBool(arg)); } else if (LogicUtil.contains(key, "push", "pushing")) { CollisionMode mode = CollisionMode.fromPushing(ParseUtil.parseBool(arg)); this.playerCollision = this.mobCollision = this.miscCollision = mode; } else if (LogicUtil.contains(key, "speedlimit", "maxspeed")) { this.setSpeedLimit(ParseUtil.parseDouble(arg, 0.4)); } else if (LogicUtil.contains(key, "allowmanual", "manualmove", "manual")) { this.allowManualMovement = ParseUtil.parseBool(arg); } else if (LogicUtil.contains(key, "keepcloaded", "loadchunks", "keeploaded")) { this.keepChunksLoaded = ParseUtil.parseBool(arg); } else if (key.equals("addtag")) { this.addTags(arg); } else if (key.equals("settag")) { this.setTags(arg); } else if (key.equals("destination")) { this.setDestination(arg); } else if (key.equals("remtag")) { this.removeTags(arg); } else if (LogicUtil.contains(key, "name", "rename", "setname")) { this.setName(generateTrainName(arg)); } else if (LogicUtil.contains(key, "dname", "displayname", "setdisplayname", "setdname")) { this.setDisplayName(arg); } else if (LogicUtil.contains(key, "mobenter", "mobsenter")) { this.mobCollision = CollisionMode.fromEntering(ParseUtil.parseBool(arg)); } else if (key.equals("playerenter")) { this.setPlayersEnter(ParseUtil.parseBool(arg)); } else if (key.equals("playerexit")) { this.setPlayersExit(ParseUtil.parseBool(arg)); } else if (LogicUtil.contains(key, "invincible", "godmode")) { this.setInvincible(ParseUtil.parseBool(arg)); } else if (key.equals("setownerperm")) { for (CartProperties prop : this) { prop.clearOwnerPermissions(); prop.getOwnerPermissions().add(arg); } } else if (key.equals("addownerperm")) { for (CartProperties prop : this) { prop.getOwnerPermissions().add(arg); } } else if (key.equals("remownerperm")) { for (CartProperties prop : this) { prop.getOwnerPermissions().remove(arg); } } else if (key.equals("setowner")) { arg = arg.toLowerCase(); for (CartProperties cprop : this) { cprop.clearOwners(); cprop.getOwners().add(arg); } } else if (key.equals("addowner")) { arg = arg.toLowerCase(); for (CartProperties cprop : this) { cprop.getOwners().add(arg); } } else if (key.equals("remowner")) { arg = arg.toLowerCase(); for (CartProperties cprop : this) { cprop.getOwners().remove(arg); } } else if (LogicUtil.contains(key, "spawnitemdrops", "spawndrops", "killdrops")) { this.setSpawnItemDrops(ParseUtil.parseBool(arg)); } else { return false; } return true; }
public boolean isTrainRenamed() { return !this.trainname.startsWith("train") || !ParseUtil.isNumeric(this.trainname.substring(5)); }
@Override public void execute(SignActionEvent info) { if (!info.isAction( SignActionType.MEMBER_ENTER, SignActionType.REDSTONE_ON, SignActionType.GROUP_ENTER)) { return; } // parse the sign boolean docart = info.isAction(SignActionType.MEMBER_ENTER, SignActionType.REDSTONE_ON) && info.isCartSign() && info.hasMember(); boolean dotrain = !docart && info.isAction(SignActionType.GROUP_ENTER, SignActionType.REDSTONE_ON) && info.isTrainSign() && info.hasGroup(); if (!docart && !dotrain) return; if (!info.isPowered()) return; // get nearby chests int radius = ParseUtil.parseInt(info.getLine(1), TrainCarts.defaultTransferRadius); List<Chest> chests = new ArrayList<Chest>(); for (BlockState state : TransferSignUtil.getBlockStates(info, radius, radius)) { if (state instanceof Chest) { chests.add((Chest) state); } } if (chests.isEmpty()) { return; } List<MinecartMember<?>> carts; if (dotrain) { carts = info.getGroup(); } else { carts = new ArrayList<MinecartMember<?>>(1); carts.add(info.getMember()); } int i; boolean found = false; for (MinecartMember<?> cart : carts) { if (!(cart instanceof MinecartMemberFurnace)) { continue; } MinecartMemberFurnace member = (MinecartMemberFurnace) cart; if (!member.getEntity().hasFuel()) { found = false; for (Chest chest : chests) { Inventory inv = chest.getInventory(); for (i = 0; i < inv.getSize(); i++) { org.bukkit.inventory.ItemStack item = inv.getItem(i); if (!LogicUtil.nullOrEmpty(item) && item.getType() == Material.COAL) { ItemUtil.subtractAmount(item, 1); inv.setItem(i, item); found = true; member.addFuelTicks(3600); if (TrainCarts.showTransferAnimations) { ItemAnimation.start(chest, member, new ItemStack(Material.COAL, 1)); } break; } } if (found) { break; } } } } }
public Station(SignActionEvent info) { this.delay = ParseUtil.parseTime(info.getLine(2)); this.nextDirection = Direction.parse(info.getLine(3)); this.centerCart = info.isCartSign() ? info.getMember() : info.getGroup().middle(); this.railsBlock = info.getRails(); // Vertical or horizontal rail logic if (info.isVerticalRails()) { this.railDirection = BlockFace.DOWN; // Up, down or center based on redstone power boolean up = info.isPowered(BlockFace.UP); boolean down = info.isPowered(BlockFace.DOWN); if (up && !down) { this.instruction = BlockFace.UP; } else if (!up && down) { this.instruction = BlockFace.DOWN; } else if (info.isPowered()) { this.instruction = BlockFace.SELF; } else { this.instruction = null; } } else { this.railDirection = info.getRailDirection(); if (FaceUtil.isSubCardinal(this.railDirection) && FaceUtil.isSubCardinal(info.getFacing())) { // Sub-cardinal checks: Both directions have two possible powered sides BlockFace[] faces = FaceUtil.getFaces(this.railDirection); boolean pow1 = info.isPowered(faces[0]) || info.isPowered(faces[1].getOppositeFace()); boolean pow2 = info.isPowered(faces[1]) || info.isPowered(faces[0].getOppositeFace()); if (pow1 && !pow2) { this.instruction = FaceUtil.combine(faces[0], faces[1].getOppositeFace()); } else if (!pow1 && pow2) { this.instruction = FaceUtil.combine(faces[0].getOppositeFace(), faces[1]); } else if (info.isPowered()) { this.instruction = BlockFace.SELF; } else { this.instruction = null; } } else { // Which directions to move, or brake? if (this.railDirection == BlockFace.WEST) { boolean west = info.isPowered(BlockFace.WEST); boolean east = info.isPowered(BlockFace.EAST); if (west && !east) { this.instruction = BlockFace.WEST; } else if (east && !west) { this.instruction = BlockFace.EAST; } else if (info.isPowered()) { this.instruction = BlockFace.SELF; } else { this.instruction = null; } } else if (this.railDirection == BlockFace.SOUTH) { boolean north = info.isPowered(BlockFace.NORTH); boolean south = info.isPowered(BlockFace.SOUTH); if (north && !south) { this.instruction = BlockFace.NORTH; } else if (south && !north) { this.instruction = BlockFace.SOUTH; } else if (info.isPowered()) { this.instruction = BlockFace.SELF; } else { this.instruction = null; } } else { this.length = 0.0; this.instruction = null; this.valid = false; return; } } } // Get initial station length, delay and direction double length = ParseUtil.parseDouble(info.getLine(1).substring(7), 0.0); if (length == 0.0 && this.instruction != null) { // Manually calculate the length // Use the amount of straight blocks if (info.isVerticalRails()) { length = this.calcVerticalLength(); } else if (FaceUtil.isSubCardinal(this.railDirection)) { length = this.calcDiagonalLength(); } else { length = this.calcHorizontalLength(); } if (length == 0.0) { length++; } } this.length = length; this.valid = true; }