static void ZoneRemoveHandler(Player player, Command cmd) { string zoneName = cmd.Next(); if (zoneName == null) { CdZoneRemove.PrintUsage(player); return; } ZoneCollection zones = player.WorldMap.Zones; Zone zone = zones.Find(zoneName); if (zone != null) { if (!player.Info.Rank.AllowSecurityCircumvention) { switch (zone.Controller.CheckDetailed(player.Info)) { case SecurityCheckResult.BlackListed: player.Message("You are not allowed to remove zone {0}: you are blacklisted.", zone.ClassyName); return; case SecurityCheckResult.RankTooLow: player.Message("You are not allowed to remove zone {0}.", zone.ClassyName); return; } } if (!cmd.IsConfirmed) { player.Confirm(cmd, "Remove zone {0}&S?", zone.ClassyName); return; } if (zones.Remove(zone.Name)) { player.Message("Zone \"{0}\" removed.", zone.Name); } } else { player.MessageNoZone(zoneName); } }
private static void SpringHandler(Player player, Command cmd) //for /spring { string revolutions = cmd.Next(); int rev; bool parsed = Int32.TryParse(revolutions, out rev); //tries to convert input to int if (player.Can(Permission.DrawAdvanced)) { PrepareSpring.SetParametrization(player, new Command("/scp x=(1+0.2*cos(2*pi*v))*sin(2*pi*u)")); PrepareSpring.SetParametrization(player, new Command("/scp y=(1+0.2*cos(2*pi*v))*cos(2*pi*u)")); PrepareSpring.SetParametrization(player, new Command("/scp z=u+0.2*sin(2*pi*v)")); if (revolutions == null || rev == 1) //if number of revolutions isnt specified, just does 1 { PrepareSpring.SetParamIteration(player, new Command("/spi u 0 1 0.005")); PrepareSpring.SetParamIteration(player, new Command("/spi v 0 1 0.005")); } else if (rev > 9 || rev <= 0) //The greatest number of revolutions without having to adjust the number of iteration steps. I would adjust the number { // of iterations per requested number of revolutions, but it would make the spring look like the blocks were placed too sparingly. player.Message("The number of revolutions must be between 1 and 9."); return; } else if (rev > 1 && rev < 5) //different amount of iteration steps when different number of revolutions. Makes the springs look more filled in. { PrepareSpring.SetParamIteration(player, new Command("/spi u 0 " + rev + " 0.005")); PrepareSpring.SetParamIteration(player, new Command("/spi v 0 " + rev + " 0.005")); } else if (rev <= 9 && rev >= 5) //different amount of iteration steps when different number of revolutions. Makes the springs look more filled in. { PrepareSpring.SetParamIteration(player, new Command("/spi u 0 " + rev + " 0.0099")); PrepareSpring.SetParamIteration(player, new Command("/spi v 0 " + rev + " 0.0099")); } StartCmdDraw(player, new Command("/spd uu")); //uses custom handler as to not display messages to the user } else { CdSpring.PrintUsage(player); } }
static void ZoneRenameHandler(Player player, Command cmd) { World playerWorld = player.World; if (playerWorld == null) { PlayerOpException.ThrowNoWorld(player); } // make sure that both parameters are given string oldName = cmd.Next(); string newName = cmd.Next(); if (oldName == null || newName == null) { CdZoneRename.PrintUsage(player); return; } // make sure that the new name is valid if (!World.IsValidName(newName)) { player.Message("\"{0}\" is not a valid zone name", newName); return; } // find the old zone var zones = player.WorldMap.Zones; Zone oldZone = zones.Find(oldName); if (oldZone == null) { player.MessageNoZone(oldName); return; } // Check if a zone with "newName" name already exists Zone newZone = zones.FindExact(newName); if (newZone != null && newZone != oldZone) { player.Message("A zone with the name \"{0}\" already exists.", newName); return; } // check if any change is needed string fullOldName = oldZone.Name; if (fullOldName == newName) { player.Message("The zone is already named \"{0}\"", fullOldName); return; } // actually rename the zone zones.Rename(oldZone, newName); // announce the rename playerWorld.Players.Message("&SZone \"{0}\" was renamed to \"{1}&S\" by {2}", 0, fullOldName, oldZone.ClassyName, player.ClassyName); Logger.Log(LogType.UserActivity, "Player {0} renamed zone \"{1}\" to \"{2}\" on world {3}", player.Name, fullOldName, newName, playerWorld.Name); }
static void ZoneEditHandler(Player player, Command cmd) { bool changesWereMade = false; string zoneName = cmd.Next(); if (zoneName == null) { player.Message("No zone name specified. See &H/Help ZEdit"); return; } Zone zone = player.WorldMap.Zones.Find(zoneName); if (zone == null) { player.MessageNoZone(zoneName); return; } string name; while ((name = cmd.Next()) != null) { if (name.StartsWith("+")) { if (name.Length == 1) { CdZoneEdit.PrintUsage(player); break; } PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name.Substring(1)); if (info == null) { return; } // prevent players from whitelisting themselves to bypass protection if (!player.Info.Rank.AllowSecurityCircumvention && player.Info == info) { if (!zone.Controller.Check(info)) { player.Message("You must be {0}+&S to add yourself to this zone's whitelist.", zone.Controller.MinRank.ClassyName); continue; } } switch (zone.Controller.Include(info)) { case PermissionOverride.Deny: player.Message("{0}&S is no longer excluded from zone {1}", info.ClassyName, zone.ClassyName); changesWereMade = true; break; case PermissionOverride.None: player.Message("{0}&S is now included in zone {1}", info.ClassyName, zone.ClassyName); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is already included in zone {1}", info.ClassyName, zone.ClassyName); break; } } else if (name.StartsWith("-")) { if (name.Length == 1) { CdZoneEdit.PrintUsage(player); break; } PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name.Substring(1)); if (info == null) { return; } switch (zone.Controller.Exclude(info)) { case PermissionOverride.Deny: player.Message("{0}&S is already excluded from zone {1}", info.ClassyName, zone.ClassyName); break; case PermissionOverride.None: player.Message("{0}&S is now excluded from zone {1}", info.ClassyName, zone.ClassyName); changesWereMade = true; break; case PermissionOverride.Allow: player.Message("{0}&S is no longer included in zone {1}", info.ClassyName, zone.ClassyName); changesWereMade = true; break; } } else if (name.ToLower().StartsWith("msg=")) { zone.Message = name.Substring(4) + " " + (cmd.NextAll() ?? ""); changesWereMade = true; player.Message("Zedit: Custom denied messaged changed to '" + zone.Message + "'"); break; } else { Rank minRank = RankManager.FindRank(name); if (minRank != null) { // prevent players from lowering rank so bypass protection if (!player.Info.Rank.AllowSecurityCircumvention && zone.Controller.MinRank > player.Info.Rank && minRank <= player.Info.Rank) { player.Message("You are not allowed to lower the zone's rank."); continue; } if (zone.Controller.MinRank != minRank) { zone.Controller.MinRank = minRank; player.Message("Permission for zone \"{0}\" changed to {1}+", zone.Name, minRank.ClassyName); changesWereMade = true; } } else { player.MessageNoRank(name); } } } if (changesWereMade) { zone.Edit(player.Info); } else { player.Message("No changes were made to the zone."); } }
static void ZoneAddHandler(Player player, Command cmd) { World playerWorld = player.World; if (playerWorld == null) { PlayerOpException.ThrowNoWorld(player); } string givenZoneName = cmd.Next(); if (givenZoneName == null) { CdZoneAdd.PrintUsage(player); return; } if (!player.Info.Rank.AllowSecurityCircumvention) { SecurityCheckResult buildCheck = playerWorld.BuildSecurity.CheckDetailed(player.Info); switch (buildCheck) { case SecurityCheckResult.BlackListed: player.Message("Cannot add zones to world {0}&S: You are barred from building here.", playerWorld.ClassyName); return; case SecurityCheckResult.RankTooLow: player.Message("Cannot add zones to world {0}&S: You are not allowed to build here.", playerWorld.ClassyName); return; //case SecurityCheckResult.RankTooHigh: } } Zone newZone = new Zone(); ZoneCollection zoneCollection = player.WorldMap.Zones; if (givenZoneName.StartsWith("+")) { // personal zone (/ZAdd +Name) givenZoneName = givenZoneName.Substring(1); // Find the target player PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, givenZoneName); if (info == null) { return; } // Make sure that the name is not taken already. // If a zone named after the player already exists, try adding a number after the name (e.g. "Notch2") newZone.Name = info.Name; for (int i = 2; zoneCollection.Contains(newZone.Name); i++) { newZone.Name = givenZoneName + i; } newZone.Controller.MinRank = info.Rank.NextRankUp ?? info.Rank; newZone.Controller.Include(info); player.Message("Zone: Creating a {0}+&S zone for player {1}&S.", newZone.Controller.MinRank.ClassyName, info.ClassyName); } else { // Adding an ordinary, rank-restricted zone. if (!World.IsValidName(givenZoneName)) { player.Message("\"{0}\" is not a valid zone name", givenZoneName); return; } if (zoneCollection.Contains(givenZoneName)) { player.Message("A zone with this name already exists. Use &H/ZEdit&S to edit."); return; } newZone.Name = givenZoneName; string rankName = cmd.Next(); if (rankName == null) { player.Message("No rank was specified. See &H/Help zone"); return; } Rank minRank = RankManager.FindRank(rankName); if (minRank != null) { string name; while ((name = cmd.Next()) != null) { if (name.Length == 0) { continue; } if (name.ToLower().StartsWith("msg=")) { newZone.Message = name.Substring(4) + " " + (cmd.NextAll() ?? ""); player.Message("Zone: Custom denied messaged changed to '" + newZone.Message + "'"); break; } PlayerInfo info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name.Substring(1)); if (info == null) { return; } if (name.StartsWith("+")) { newZone.Controller.Include(info); } else if (name.StartsWith("-")) { newZone.Controller.Exclude(info); } } newZone.Controller.MinRank = minRank; } else { player.MessageNoRank(rankName); return; } } player.Message("Zone " + newZone.ClassyName + "&S: Place a block or type &H/Mark&S to use your location."); player.SelectionStart(2, ZoneAddCallback, newZone, CdZoneAdd.Permissions); }
private static void PolarRoseHandler(Player player, Command cmd) { //prepping variables, converting them to ints to enter into the equations string petals = cmd.Next(); int pet; bool parsedPet = Int32.TryParse(petals, out pet); int petTest = (pet / 2); string length = cmd.Next(); int len; bool parsedLen = Int32.TryParse(length, out len); string revolutions = cmd.Next(); int rev; bool parsedRev = Int32.TryParse(revolutions, out rev); double numRev = (6.28 * rev); string Height = cmd.Next(); int height; bool parsedHeight = Int32.TryParse(Height, out height); double NumHeight = (height * 0.01); //This makes the Height more managable for the user double RevIter = (0.01 + (rev * 0.005)); //Iteration needs to be adjusted based on how many revolutions are made. double RevIter6 = (rev * 0.015); //Seperate RevIter for when 6 petals (required because of method used for 6 petals) if (player.Can(Permission.DrawAdvanced) && pet > 2 && len > 0 && len < 5 && rev > 0 && rev < 5) { if (!parsedPet || !parsedLen || !parsedRev) //if the player enters in invalid values for length or number of petals { player.Message("Please enter whole number values for each of the variables. (Height is optional) Type /help pr for the ranges."); return; } if (petals == null || length == null || revolutions == null) { player.Message("Please enter values for number of petals, length of petals and number of revolutions."); } if (pet == 4 || pet == 8 || pet == 10 || pet == 12 || pet == 14 || pet == 16) //When the number of petals is even, the number entered has to be halved to get the { //right number of petals. I figured numbers over 16, the user wouldn't even notice. PrepareSpring.SetParametrization(player, new Command("/scp x=" + len + "*sin(" + petTest + "*u)*cos(u)")); PrepareSpring.SetParametrization(player, new Command("/scp y=" + len + "*sin(" + petTest + "*u)*sin(u)")); } else if (pet == 6) //The math behind this is complicated, but getting 6 petals with this method is impossible. I am using a different method { //for when the user asks for 6 petals. They will be slightly overlapping, unlike the others. PrepareSpring.SetParametrization(player, new Command("/scp x=" + len + "*sin(1.5*u)*cos(u)")); PrepareSpring.SetParametrization(player, new Command("/scp y=" + len + "*sin(1.5*u)*sin(u)")); } else { PrepareSpring.SetParametrization(player, new Command("/scp x=" + len + "*sin(" + pet + "*u)*cos(u)")); PrepareSpring.SetParametrization(player, new Command("/scp y=" + len + "*sin(" + pet + "*u)*sin(u)")); } if (Height == null || Height.Length == 0) //If no height is specified, the rose will be flat. { PrepareSpring.SetParametrization(player, new Command("/scp z=0")); } else if (Height.Length >= 1 && parsedHeight) { PrepareSpring.SetParametrization(player, new Command("/scp z=" + NumHeight + "*u")); } else { player.Message("Please enter whole integer values for each of the variables. (Height is optional) Type /help pr for the ranges."); return; } if (pet == 6) { PrepareSpring.SetParamIteration(player, new Command("/spi u 0 12.56 " + RevIter6)); PrepareSpring.SetParamIteration(player, new Command("/spi v 0 12.56 " + RevIter6)); } else { PrepareSpring.SetParamIteration(player, new Command("/spi u 0 " + numRev + " " + RevIter)); PrepareSpring.SetParamIteration(player, new Command("/spi v 0 " + numRev + " " + RevIter)); } StartCmdDraw(player, new Command("/spd uu")); //uses custom handler as to not display messages to user } else if (pet < 3 || len < 1 || len > 4 || rev < 0 || height < 1 || rev > 4) { player.Message("&cRanges: &hPetals[3,infinity), Length[1,4], Revolutions[1,4), Height[1,infinity)."); return; } else { CdPolarRose.PrintUsage(player); } }