/** * Saves an anchor. * @param anchor The name of the anchor. * @param location The location of the anchor as string. * @return True if the anchor was successfully saved. */ public boolean saveAnchorLocation(String anchor, String location) { Location parsed = plugin.getLocationManipulation().stringToLocation(location); return parsed != null && this.saveAnchorLocation(anchor, parsed); }
/** * Saves an anchor. * @param anchor The name of the anchor. * @param l The {@link Location} of the anchor. * @return True if the anchor was successfully saved. */ public boolean saveAnchorLocation(String anchor, Location l) { if (l == null) { return false; } this.anchorConfig.set("anchors." + anchor, plugin.getLocationManipulation().locationToString(l)); this.anchors.put(anchor, l); return this.saveAnchors(); }
/** * Loads all anchors. */ public void loadAnchors() { this.anchors = new HashMap<String, Location>(); this.anchorConfig = YamlConfiguration.loadConfiguration(new File(this.plugin.getDataFolder(), "anchors.yml")); this.ensureConfigIsPrepared(); ConfigurationSection anchorsSection = this.anchorConfig.getConfigurationSection("anchors"); Set<String> anchorKeys = anchorsSection.getKeys(false); for (String key : anchorKeys) { //world:x,y,z:pitch:yaw Location anchorLocation = plugin.getLocationManipulation().stringToLocation(anchorsSection.getString(key, "")); if (anchorLocation != null) { Logging.config("Loading anchor: '%s'...", key); this.anchors.put(key, anchorLocation); } else { Logging.warning("The location for anchor '%s' is INVALID.", key); } } }
@Override public Location validateChange(String property, Location newValue, Location oldValue, MVWorld object) throws ChangeDeniedException { if (newValue == null) throw new ChangeDeniedException(); if (props.getAdjustSpawn()) { BlockSafety bs = plugin.getBlockSafety(); // verify that the location is safe if (!bs.playerCanSpawnHereSafely(newValue)) { // it's not ==> find a better one! plugin.log(Level.WARNING, String.format("Somebody tried to set the spawn location for '%s' to an unsafe value! Adjusting...", getAlias())); plugin.log(Level.WARNING, "Old Location: " + plugin.getLocationManipulation().strCoordsRaw(oldValue)); plugin.log(Level.WARNING, "New (unsafe) Location: " + plugin.getLocationManipulation().strCoordsRaw(newValue)); SafeTTeleporter teleporter = plugin.getSafeTTeleporter(); newValue = teleporter.getSafeLocation(newValue, SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS); if (newValue == null) { plugin.log(Level.WARNING, "Couldn't fix the location. I have to abort the spawn location-change :/"); throw new ChangeDeniedException(); } plugin.log(Level.WARNING, "New (safe) Location: " + plugin.getLocationManipulation().strCoordsRaw(newValue)); } } return super.validateChange(property, newValue, oldValue, object); } }
/** * {@inheritDoc} */ @Override public Location getSafeLocation(Location l, int tolerance, int radius) { // Check around the player first in a configurable radius: // TODO: Make this configurable Location safe = checkAboveAndBelowLocation(l, tolerance, radius); if (safe != null) { safe.setX(safe.getBlockX() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck safe.setZ(safe.getBlockZ() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck this.plugin.log(Level.FINE, "Hey! I found one: " + plugin.getLocationManipulation().strCoordsRaw(safe)); } else { this.plugin.log(Level.FINE, "Uh oh! No safe place found!"); } return safe; }
message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors)); message.add(new FancyMessage("World Scale: ", String.valueOf(world.getScaling()), colors)); message.add(new FancyMessage("World Seed: ", String.valueOf(world.getSeed()), colors));
@Override public void runCommand(CommandSender sender, List<String> args) { // Check if the command was sent from a Player. if (sender instanceof Player) { Player p = (Player) sender; World world = p.getWorld(); if (!this.worldManager.isMVWorld(world.getName())) { this.plugin.showNotMVWorldMessage(sender, world.getName()); return; } MultiverseWorld mvworld = this.worldManager.getMVWorld(world.getName()); p.sendMessage(ChatColor.AQUA + "--- Location Information ---"); p.sendMessage(ChatColor.AQUA + "World: " + ChatColor.WHITE + world.getName()); p.sendMessage(ChatColor.AQUA + "Alias: " + mvworld.getColoredWorldString()); p.sendMessage(ChatColor.AQUA + "World Scale: " + ChatColor.WHITE + mvworld.getScaling()); DecimalFormat df = new DecimalFormat(); df.setMinimumFractionDigits(0); df.setMaximumFractionDigits(2); p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + plugin.getLocationManipulation().strCoords(p.getLocation())); p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + plugin.getLocationManipulation().getDirection(p.getLocation())); p.sendMessage(ChatColor.AQUA + "Block: " + ChatColor.WHITE + world.getBlockAt(p.getLocation()).getType()); } else { sender.sendMessage("This command needs to be used from a Player."); } } }
this.plugin.log(Level.WARNING, "Original Location: " + plugin.getLocationManipulation().strCoordsRaw(location)); Location newSpawn = teleporter.getSafeLocation(location, SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS); this.getName(), plugin.getLocationManipulation().locationToString(newSpawn)); return newSpawn; } else { if (newerSpawn != null) { Logging.info("New Spawn for '%s' is located at: %s", this.getName(), plugin.getLocationManipulation().locationToString(newerSpawn)); return newerSpawn; } else {
if (result == TeleportResult.FAIL_UNSAFE) { this.plugin.log(Level.FINE, "Could not teleport " + teleportee.getName() + " to " + plugin.getLocationManipulation().strCoordsRaw(d.getLocation(teleportee))); this.plugin.log(Level.FINE, "Queueing Command"); Class<?>[] paramTypes = { CommandSender.class, Player.class, Location.class };
this.plugin.log(Level.FINER, "Given Location of: " + plugin.getLocationManipulation().strCoordsRaw(l)); this.plugin.log(Level.FINER, "Checking +-" + tolerance + " with a radius of " + radius);
foundWorld.setAdjustSpawn(false); sender.sendMessage("Spawn was set to: " + plugin.getLocationManipulation().strCoords(p.getLocation())); if (!plugin.saveWorldConfig()) { sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!");