mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Abstract some parts of level searching and level property finding to new LevelInfo class.
This commit is contained in:
parent
2e53946e4d
commit
354404bdd5
@ -385,7 +385,7 @@ namespace MCGalaxy.Commands {
|
||||
Economy.UpdateEcoStats(ecos);
|
||||
Command.all.Find("load").Use(null, p.name + "_" + par3);
|
||||
Thread.Sleep(250);
|
||||
Level level = Level.Find(p.name + "_" + par3);
|
||||
Level level = LevelInfo.Find(p.name + "_" + par3);
|
||||
if (level.permissionbuild > p.group.Permission) { level.permissionbuild = p.group.Permission; }
|
||||
if (level.permissionvisit > p.group.Permission) { level.permissionvisit = p.group.Permission; }
|
||||
Command.all.Find("goto").Use(p, p.name + "_" + par3);
|
||||
|
@ -312,7 +312,7 @@ namespace MCGalaxy.Commands
|
||||
try
|
||||
{
|
||||
Command.all.Find("load").Use(null, "countdown");
|
||||
Server.Countdown.mapon = Level.FindExact("countdown");
|
||||
Server.Countdown.mapon = LevelInfo.FindExact("countdown");
|
||||
Server.Countdown.gamestatus = CountdownGameStatus.Enabled;
|
||||
Player.GlobalMessage("Countdown has been enabled!!");
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ namespace MCGalaxy.Commands
|
||||
if (s[1] == "map")
|
||||
{
|
||||
if (s.Length < 3) { SetupHelp(p, "map"); return; }
|
||||
Level foundLevel = Level.Find(s[2]);
|
||||
Level foundLevel = LevelInfo.Find(s[2]);
|
||||
if (foundLevel == null)
|
||||
{
|
||||
Player.SendMessage(p, "The level must be loaded to add/remove it.");
|
||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy.Commands
|
||||
|
||||
if (who == null)
|
||||
{
|
||||
Level which = Level.Find(message);
|
||||
Level which = LevelInfo.Find(message);
|
||||
|
||||
if (which == null)
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
Level lvl = Level.Find(text[1]);
|
||||
Level lvl = LevelInfo.Find(text[1]);
|
||||
if (lvl == null)
|
||||
{
|
||||
Player.SendMessage(p, "TNT Wars Error: Couldn't find level '" + text[1] + "'");
|
||||
@ -673,7 +673,7 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
it.lvl = Level.Find(text[2]);
|
||||
it.lvl = LevelInfo.Find(text[2]);
|
||||
if (it.lvl == null)
|
||||
{
|
||||
Player.SendMessage(p, "TNT Wars Error: '" + text[2] + "' is not a level!");
|
||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
public override void Use(Player p, string message)
|
||||
{
|
||||
Level lvl = message == "" ? p.level : Level.Find(message);
|
||||
Level lvl = message == "" ? p.level : LevelInfo.Find(message);
|
||||
if (lvl == null) { Player.SendMessage(p, "Could not find specified level."); return; }
|
||||
|
||||
Player.SendMessage(p, "&b" + lvl.name + Server.DefaultColor + ": Width=" + lvl.Width + " Height=" + lvl.Height + " Depth=" + lvl.Length);
|
||||
|
@ -96,62 +96,28 @@ namespace MCGalaxy.Commands
|
||||
//Exception catching since it needs to be tested on Ocean Flatgrass
|
||||
}
|
||||
|
||||
private LevelPermission GetPerVisitPermission(string level) {
|
||||
string location = "levels/level properties/" + level + ".properties";
|
||||
LevelPermission lvlperm = LevelPermission.Guest;
|
||||
try {
|
||||
using (StreamReader reader = new StreamReader(location)) {
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null) {
|
||||
if (line.Split()[0].ToLower() == "pervisit") {
|
||||
lvlperm = Group.Find(line.Split()[2]).Permission;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch { return LevelPermission.Guest; }
|
||||
|
||||
return lvlperm;
|
||||
LevelPermission GetPerVisitPermission(string level) {
|
||||
string value = LevelInfo.FindOfflineProperty(level, "pervisit");
|
||||
if (value == null) return LevelPermission.Guest;
|
||||
Group grp = Group.Find(value);
|
||||
return grp == null ? LevelPermission.Guest : grp.Permission;
|
||||
}
|
||||
|
||||
private LevelPermission GetPerBuildPermission(string level) {
|
||||
string location = "levels/level properties/" + level + ".properties";
|
||||
LevelPermission lvlperm = LevelPermission.Guest;
|
||||
try {
|
||||
using (StreamReader reader = new StreamReader(location)) {
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null) {
|
||||
if (line.Split()[0].ToLower() == "perbuild") {
|
||||
lvlperm = Group.Find(line.Split()[2]).Permission;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch { return LevelPermission.Guest; }
|
||||
|
||||
return lvlperm;
|
||||
LevelPermission GetPerBuildPermission(string level) {
|
||||
string value = LevelInfo.FindOfflineProperty(level, "perbuild");
|
||||
if (value == null) return LevelPermission.Guest;
|
||||
Group grp = Group.Find(value);
|
||||
return grp == null ? LevelPermission.Guest : grp.Permission;
|
||||
}
|
||||
|
||||
private bool GetLoadOnGoto(string level) {
|
||||
string location = "levels/level properties/" + level + ".properties";
|
||||
bool loadOnGoto = false;
|
||||
try {
|
||||
using (StreamReader reader = new StreamReader(location)) {
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null) {
|
||||
if (line.Split()[0].ToLower() == "loadongoto") {
|
||||
loadOnGoto = bool.Parse(line.Split()[2]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch { return false; }
|
||||
|
||||
return loadOnGoto;
|
||||
bool GetLoadOnGoto(string level) {
|
||||
string value = LevelInfo.FindOfflineProperty(level, "loadongoto");
|
||||
bool load;
|
||||
if (!bool.TryParse(value, out load)) return true;
|
||||
return load;
|
||||
}
|
||||
|
||||
public override void Help(Player p)
|
||||
{
|
||||
public override void Help(Player p) {
|
||||
Player.SendMessage(p, "%f/unloaded " + Server.DefaultColor + "- Lists all unloaded levels and their accessible state.");
|
||||
Player.SendMessage(p, "%f/unloaded <1/2/3/..> " + Server.DefaultColor + "- Shows a compact list.");
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
lvl = p.level;
|
||||
} else {
|
||||
lvl = Level.Find(message);
|
||||
lvl = LevelInfo.Find(message);
|
||||
if (lvl == null || !File.Exists("levels/" + message + ".lvl")) {
|
||||
Player.SendMessage(p, "&9The level, &c" + message + " &9does not exist!"); return;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ namespace MCGalaxy.Commands
|
||||
try
|
||||
{
|
||||
Pos = who.UndoBuffer[CurrentPos];
|
||||
Level foundLevel = Level.Find(Pos.mapName);
|
||||
Level foundLevel = LevelInfo.Find(Pos.mapName);
|
||||
if (foundLevel == p.level)
|
||||
{
|
||||
b = foundLevel.GetTile(Pos.x, Pos.y, Pos.z);
|
||||
@ -153,7 +153,7 @@ namespace MCGalaxy.Commands
|
||||
{
|
||||
if (Convert.ToDateTime(fileContent[(i * 7) + 4].Replace('&', ' ')).AddSeconds(seconds) >= DateTime.Now)
|
||||
{
|
||||
Level foundLevel = Level.Find(fileContent[i * 7]);
|
||||
Level foundLevel = LevelInfo.Find(fileContent[i * 7]);
|
||||
if (foundLevel != null && foundLevel == p.level)
|
||||
{
|
||||
Pos.mapName = foundLevel.name;
|
||||
|
@ -26,7 +26,7 @@ namespace MCGalaxy.Commands
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
public override void Use(Player p, string message)
|
||||
{
|
||||
Level level = Level.Find(message.Split(' ')[0]);
|
||||
Level level = LevelInfo.Find(message.Split(' ')[0]);
|
||||
if (level == null) { Player.SendMessage(p, "There is no level named '" + message.Split(' ')[0] + "'."); return; }
|
||||
if (p == null)
|
||||
foreach (Player pl in PlayerInfo.players) { Command.all.Find("move").Use(null, pl.name + " " + level.name); }
|
||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy.Commands
|
||||
public override void Use(Player p, string message)
|
||||
{
|
||||
if (message == "" || message.IndexOf(' ') == -1) { Help(p); return; }
|
||||
Level foundLevel = Level.Find(message.Split(' ')[0]);
|
||||
Level foundLevel = LevelInfo.Find(message.Split(' ')[0]);
|
||||
if (foundLevel == null)
|
||||
{
|
||||
Player.SendMessage(p, "Level not found");
|
||||
|
@ -35,7 +35,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
Level lvl = null;
|
||||
if (parts.Length == 2) {
|
||||
lvl = Level.Find(parts[1]);
|
||||
lvl = LevelInfo.Find(parts[1]);
|
||||
} else if (p != null && p.level != null) {
|
||||
lvl = p.level;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
Level lvl = p == null ? null : p.level;
|
||||
if (message != "") {
|
||||
lvl = Level.Find(message.ToLower());
|
||||
lvl = LevelInfo.Find(message.ToLower());
|
||||
if (lvl == null) {
|
||||
Player.SendMessage(p, "Could not find the entered level."); return;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (message == "" || message.Split().Length > 1) { Help(p); return; }
|
||||
Level foundLevel = Level.Find(message);
|
||||
Level foundLevel = LevelInfo.Find(message);
|
||||
if (foundLevel != null) {
|
||||
if (foundLevel.permissionbuild > p.group.Permission) {
|
||||
Player.SendMessage(p, "%cYou can't delete levels with a perbuild rank higher than yours!");
|
||||
|
@ -32,12 +32,12 @@ namespace MCGalaxy.Commands {
|
||||
if (p == null) { MessageInGameOnly(p); return; }
|
||||
if (message == "") { Help(p); return; }
|
||||
|
||||
Level lvl = Level.FindExact(message);
|
||||
Level lvl = LevelInfo.FindExact(message);
|
||||
if (lvl != null) {
|
||||
GoToLevel(p, lvl, message);
|
||||
} else if (Server.AutoLoad) {
|
||||
if (!File.Exists("levels/" + message + ".lvl")) {
|
||||
lvl = Level.Find(message);
|
||||
lvl = LevelInfo.Find(message);
|
||||
if (lvl == null) {
|
||||
Player.SendMessage(p, "Level \"" + message + "\" doesn't exist! Did you mean...");
|
||||
Command.all.Find("search").Use(p, "levels " + message);
|
||||
@ -46,7 +46,7 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
} else if (Level.CheckLoadOnGoto(message)) {
|
||||
Command.all.Find("load").Use(p, message);
|
||||
lvl = Level.Find(message);
|
||||
lvl = LevelInfo.Find(message);
|
||||
if (lvl != null) {
|
||||
GoToLevel(p, lvl, message);
|
||||
}
|
||||
@ -58,7 +58,7 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
lvl = Level.Find(message);
|
||||
lvl = LevelInfo.Find(message);
|
||||
if (lvl == null) {
|
||||
Player.SendMessage(p, "There is no level \"" + message + "\" loaded. Did you mean..");
|
||||
Command.all.Find("search").Use(p, "levels " + message);
|
||||
|
@ -33,7 +33,7 @@ namespace MCGalaxy.Commands
|
||||
|
||||
if (message.IndexOf(' ') == -1)
|
||||
{
|
||||
lvl = Level.Find(message);
|
||||
lvl = LevelInfo.Find(message);
|
||||
if (lvl == null)
|
||||
{
|
||||
if (p != null)
|
||||
@ -66,7 +66,7 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
else
|
||||
{
|
||||
lvl = Level.Find(message.Split(' ')[0]);
|
||||
lvl = LevelInfo.Find(message.Split(' ')[0]);
|
||||
|
||||
if (lvl == null || message.Split(' ')[0].ToLower() == "ps" || message.Split(' ')[0].ToLower() == "rp") lvl = p.level;
|
||||
else message = message.Substring(message.IndexOf(' ') + 1);
|
||||
|
@ -35,13 +35,13 @@ namespace MCGalaxy.Commands
|
||||
if (parts.Length == 1) {
|
||||
if (!int.TryParse(parts[0], out seconds)) {
|
||||
seconds = 30;
|
||||
lvl = Level.Find(parts[0].ToLower());
|
||||
lvl = LevelInfo.Find(parts[0].ToLower());
|
||||
}
|
||||
} else {
|
||||
if (!int.TryParse(parts[0], out seconds)) {
|
||||
Player.SendMessage(p, "You must specify pause time in seconds"); return;
|
||||
}
|
||||
lvl = Level.Find(parts[1].ToLower());
|
||||
lvl = LevelInfo.Find(parts[1].ToLower());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands {
|
||||
return;
|
||||
}
|
||||
|
||||
Level level = args.Length == 1 ? p.level : Level.Find(args[0]);
|
||||
Level level = args.Length == 1 ? p.level : LevelInfo.Find(args[0]);
|
||||
if (level == null) {
|
||||
Player.SendMessage(p, "There is no level \"" + args[0] + "\" loaded."); return;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
|
||||
if (args.Length == 2) {
|
||||
level = Level.Find(args[0].ToLower());
|
||||
level = LevelInfo.Find(args[0].ToLower());
|
||||
if (level == null) {
|
||||
Player.SendMessage(p, "Could not find entered level."); return;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace MCGalaxy.Commands
|
||||
if (message.Split(' ').Length >= 2)
|
||||
{
|
||||
|
||||
lvl = Level.Find(text[1]);
|
||||
lvl = LevelInfo.Find(text[1]);
|
||||
if (lvl == null)
|
||||
{
|
||||
Player.SendMessage(p, "Level not found!");
|
||||
|
@ -52,7 +52,7 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
}
|
||||
} else if (message.Split(' ').Length == 1) { //Just save level given
|
||||
Level foundLevel = Level.Find(message);
|
||||
Level foundLevel = LevelInfo.Find(message);
|
||||
if (foundLevel != null) {
|
||||
foundLevel.Save(true);
|
||||
Player.SendMessage(p, "Level \"" + foundLevel.name + "\" saved.");
|
||||
@ -67,7 +67,7 @@ namespace MCGalaxy.Commands
|
||||
Player.SendMessage(p, "Could not find level specified");
|
||||
}
|
||||
} else if (message.Split(' ').Length == 2) {
|
||||
Level foundLevel = Level.Find(message.Split(' ')[0]);
|
||||
Level foundLevel = LevelInfo.Find(message.Split(' ')[0]);
|
||||
string restoreName = message.Split(' ')[1].ToLower();
|
||||
if (foundLevel != null) {
|
||||
foundLevel.Save(true);
|
||||
|
@ -41,7 +41,7 @@ namespace MCGalaxy.Commands
|
||||
l.Unload(true, true);
|
||||
});
|
||||
} else {
|
||||
Level level = Level.Find(name);
|
||||
Level level = LevelInfo.Find(name);
|
||||
if (level == null) {
|
||||
Player.SendMessage(p, "There is no level \"" + name + "\" loaded.");
|
||||
} else if (!level.Unload()) {
|
||||
|
@ -33,7 +33,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
for (int i = p.RedoBuffer.Count - 1; i >= 0; i--) {
|
||||
Player.UndoPos Pos = p.RedoBuffer[i];
|
||||
Level lvl = Level.FindExact(Pos.mapName);
|
||||
Level lvl = LevelInfo.FindExact(Pos.mapName);
|
||||
if (lvl == null)
|
||||
continue;
|
||||
|
||||
|
@ -159,7 +159,7 @@ namespace MCGalaxy.Commands
|
||||
}
|
||||
|
||||
bool CheckBlockPlayer(Player p, long seconds, Player.UndoPos undo, ref Level saveLevel) {
|
||||
Level lvl = Level.FindExact(undo.mapName);
|
||||
Level lvl = LevelInfo.FindExact(undo.mapName);
|
||||
saveLevel = lvl;
|
||||
byte b = lvl.GetTile(undo.x, undo.y, undo.z);
|
||||
if (undo.timePlaced.AddSeconds(seconds) < DateTime.Now)
|
||||
|
@ -48,7 +48,7 @@ namespace MCGalaxy.Commands
|
||||
if (param.Length == 2) // /move name map
|
||||
{
|
||||
Player who = PlayerInfo.Find(param[0]);
|
||||
Level where = Level.Find(param[1]);
|
||||
Level where = LevelInfo.Find(param[1]);
|
||||
if (who == null) { Player.SendMessage(p, "Could not find player specified"); return; }
|
||||
if (where == null) { Player.SendMessage(p, "Could not find level specified"); return; }
|
||||
if (p != null && who.group.Permission > p.group.Permission) { Player.SendMessage(p, "Cannot move someone of greater rank"); return; }
|
||||
|
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands
|
||||
Player.SendMessage(p, "Warps:");
|
||||
foreach (Warp.Wrp wr in Warp.Warps)
|
||||
{
|
||||
if (Level.Find(wr.lvlname) != null)
|
||||
if (LevelInfo.Find(wr.lvlname) != null)
|
||||
{
|
||||
Player.SendMessage(p, wr.name + " : " + wr.lvlname);
|
||||
Thread.Sleep(300); // I feel this is needed so that if there are a lot of warps, they do not immediatly go off the screen!
|
||||
@ -137,7 +137,7 @@ namespace MCGalaxy.Commands
|
||||
{
|
||||
Warp.Wrp w = new Warp.Wrp();
|
||||
w = Warp.GetWarp(par0);
|
||||
Level lvl = Level.Find(w.lvlname);
|
||||
Level lvl = LevelInfo.Find(w.lvlname);
|
||||
if (lvl != null)
|
||||
{
|
||||
if (p.level != lvl)
|
||||
|
@ -83,7 +83,7 @@ namespace MCGalaxy.Commands
|
||||
Player.SendMessage(p, "Waypoints:");
|
||||
foreach (Waypoint wp in p.Waypoints)
|
||||
{
|
||||
if (Level.Find(wp.lvlname) != null)
|
||||
if (LevelInfo.Find(wp.lvlname) != null)
|
||||
{
|
||||
Player.SendMessage(p, wp.name + ":" + wp.lvlname);
|
||||
}
|
||||
|
@ -1515,9 +1515,9 @@ txtBackupLocation.Text = folderDialog.SelectedPath;
|
||||
try { name = lsMapNoUse.Items[lsMapNoUse.SelectedIndex].ToString(); }
|
||||
catch { return; }
|
||||
|
||||
if ( Level.Find(name) == null )
|
||||
if ( LevelInfo.Find(name) == null )
|
||||
Command.all.Find("load").Use(null, name);
|
||||
Level level = Level.Find(name);
|
||||
Level level = LevelInfo.Find(name);
|
||||
if ( level == null ) return;
|
||||
|
||||
Server.lava.AddMap(name);
|
||||
@ -1550,9 +1550,9 @@ txtBackupLocation.Text = folderDialog.SelectedPath;
|
||||
try { name = lsMapUse.Items[lsMapUse.SelectedIndex].ToString(); }
|
||||
catch { return; }
|
||||
|
||||
if ( Level.Find(name) == null )
|
||||
if ( LevelInfo.Find(name) == null )
|
||||
Command.all.Find("load").Use(null, name);
|
||||
Level level = Level.Find(name);
|
||||
Level level = LevelInfo.Find(name);
|
||||
if ( level == null ) return;
|
||||
|
||||
Server.lava.RemoveMap(name);
|
||||
@ -1942,7 +1942,7 @@ txtBackupLocation.Text = folderDialog.SelectedPath;
|
||||
return;
|
||||
}
|
||||
string[] split = slctd.Split(new string[] { " - " }, StringSplitOptions.None);
|
||||
TntWarsGame.GuiLoaded = TntWarsGame.Find(Level.Find(split[0]));
|
||||
TntWarsGame.GuiLoaded = TntWarsGame.Find(LevelInfo.Find(split[0]));
|
||||
LoadTNTWarsTab(sender, e);
|
||||
}
|
||||
catch { }
|
||||
@ -1955,7 +1955,7 @@ txtBackupLocation.Text = folderDialog.SelectedPath;
|
||||
private void TntWrsCrtNwTntWrsBt_Click(object sender, EventArgs e) {
|
||||
TntWarsGame it = null;
|
||||
try {
|
||||
it = new TntWarsGame(Level.Find(TntWrsMpsList.Items[TntWrsMpsList.SelectedIndex].ToString()));
|
||||
it = new TntWarsGame(LevelInfo.Find(TntWrsMpsList.Items[TntWrsMpsList.SelectedIndex].ToString()));
|
||||
}
|
||||
catch { }
|
||||
if ( it == null ) return;
|
||||
|
@ -986,7 +986,7 @@ namespace MCGalaxy.Gui
|
||||
foreach (FileInfo file in fi)
|
||||
{
|
||||
name = file.Name.Replace(".lvl", "");
|
||||
if (Level.Find(name.ToLower()) == null)
|
||||
if (LevelInfo.Find(name.ToLower()) == null)
|
||||
UnloadedList.Items.Add(name);
|
||||
}
|
||||
});
|
||||
@ -1125,9 +1125,9 @@ namespace MCGalaxy.Gui
|
||||
catch { }
|
||||
foreach (Object obj in MapCombo.Items)
|
||||
{
|
||||
if (Level.Find(obj.ToString()) != null)
|
||||
if (LevelInfo.Find(obj.ToString()) != null)
|
||||
{
|
||||
if (p.level == Level.Find(obj.ToString()))
|
||||
if (p.level == LevelInfo.Find(obj.ToString()))
|
||||
{
|
||||
MapCombo.SelectedItem = obj;
|
||||
}
|
||||
@ -1264,7 +1264,7 @@ namespace MCGalaxy.Gui
|
||||
PlayersTextBox.AppendTextAndScroll("The player is already on that map");
|
||||
return;
|
||||
}
|
||||
if (!Server.levels.Contains(Level.Find(MapCombo.Text)))
|
||||
if (!Server.levels.Contains(LevelInfo.Find(MapCombo.Text)))
|
||||
{
|
||||
PlayersTextBox.AppendTextAndScroll("That map doesn't exist!!");
|
||||
return;
|
||||
|
@ -228,7 +228,7 @@ namespace MCGalaxy
|
||||
File.Delete("levels/ctf.lvl");
|
||||
File.Copy("CTF/maps/" + mapname + ".lvl", "levels/ctf.lvl");
|
||||
Command.all.Find("load").Use(null, "ctf");
|
||||
mainlevel = Level.Find("ctf");
|
||||
mainlevel = LevelInfo.Find("ctf");
|
||||
}
|
||||
/// <summary>
|
||||
/// Create a new CTF object
|
||||
@ -272,7 +272,7 @@ namespace MCGalaxy
|
||||
tagging.Dispose();
|
||||
mainlevel = null;
|
||||
started = false;
|
||||
if (Level.Find("ctf") != null)
|
||||
if (LevelInfo.Find("ctf") != null)
|
||||
Command.all.Find("unload").Use(null, "ctf");
|
||||
}
|
||||
void tagging_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
@ -358,7 +358,7 @@ namespace MCGalaxy
|
||||
/// </summary>
|
||||
public void Start()
|
||||
{
|
||||
if (Level.Find("ctf") != null)
|
||||
if (LevelInfo.Find("ctf") != null)
|
||||
{
|
||||
Command.all.Find("unload").Use(null, "ctf");
|
||||
Thread.Sleep(1000);
|
||||
|
@ -280,7 +280,7 @@ namespace MCGalaxy
|
||||
Level oldMap = null;
|
||||
if (active && map != null) oldMap = map;
|
||||
Command.all.Find("load").Use(null, name);
|
||||
map = Level.Find(name);
|
||||
map = LevelInfo.Find(name);
|
||||
|
||||
if (map != null)
|
||||
{
|
||||
|
@ -418,7 +418,7 @@ namespace MCGalaxy
|
||||
}
|
||||
Level current = Server.mainLevel;
|
||||
|
||||
if (Server.lastLevelVote1 == level || Server.lastLevelVote2 == level2 || Server.lastLevelVote1 == level2 || Server.lastLevelVote2 == level || current == Level.Find(level) || currentZombieLevel == level || current == Level.Find(level2) || currentZombieLevel == level2)
|
||||
if (Server.lastLevelVote1 == level || Server.lastLevelVote2 == level2 || Server.lastLevelVote1 == level2 || Server.lastLevelVote2 == level || current == LevelInfo.Find(level) || currentZombieLevel == level || current == LevelInfo.Find(level2) || currentZombieLevel == level2)
|
||||
goto LevelChoice;
|
||||
else if (selectedLevel1 == "") { selectedLevel1 = level; goto LevelChoice; }
|
||||
else
|
||||
@ -565,7 +565,7 @@ namespace MCGalaxy
|
||||
String oldLevel = Server.mainLevel.name;
|
||||
if (changeMainLevel)
|
||||
{
|
||||
Server.mainLevel = Level.Find(next.ToLower());
|
||||
Server.mainLevel = LevelInfo.Find(next.ToLower());
|
||||
PlayerInfo.players.ForEach(delegate(Player player)
|
||||
{
|
||||
if (player.level.name != next && player.level.name == currentLevelName)
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
@ -375,23 +375,11 @@ namespace MCGalaxy
|
||||
return x >= 0 && y >= 0 && z >= 0 && x < Width && y < Height && z < Length;
|
||||
}
|
||||
|
||||
public static Level Find(string name) {
|
||||
name = name.ToLower();
|
||||
Level match = null; int matches = 0;
|
||||
[Obsolete]
|
||||
public static Level Find(string name) { return LevelInfo.Find(name); }
|
||||
|
||||
foreach (Level level in Server.levels) {
|
||||
if (level.name.ToLower() == name) return level;
|
||||
if (level.name.ToLower().Contains(name)) {
|
||||
match = level; matches++;
|
||||
}
|
||||
}
|
||||
return matches == 1 ? match : null;
|
||||
}
|
||||
|
||||
public static Level FindExact(string levelName)
|
||||
{
|
||||
return Server.levels.Find(lvl => levelName.ToLower() == lvl.name.ToLower());
|
||||
}
|
||||
[Obsolete]
|
||||
public static Level FindExact(string name) { return LevelInfo.FindExact(name); }
|
||||
|
||||
public static void SaveSettings(Level level) {
|
||||
LvlProperties.Save(level, "levels/level properties/" + level.name);
|
||||
@ -652,40 +640,12 @@ namespace MCGalaxy
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool CheckLoadOnGoto(string givenName)
|
||||
{
|
||||
try
|
||||
{
|
||||
string foundLocation;
|
||||
foundLocation = "levels/level properties/" + givenName + ".properties";
|
||||
if (!File.Exists(foundLocation))
|
||||
foundLocation = "levels/level properties/" + givenName;
|
||||
if (!File.Exists(foundLocation))
|
||||
return true;
|
||||
|
||||
foreach (string line in File.ReadAllLines(foundLocation))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (line[0] == '#') continue;
|
||||
string value = line.Substring(line.IndexOf(" = ") + 3);
|
||||
|
||||
switch (line.Substring(0, line.IndexOf(" = ")).ToLower())
|
||||
{
|
||||
case "loadongoto":
|
||||
return bool.Parse(value);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Server.ErrorLog(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return true;
|
||||
public static bool CheckLoadOnGoto(string givenName) {
|
||||
string value = LevelInfo.FindOfflineProperty(givenName, "loadongoto");
|
||||
if (value == null) return true;
|
||||
bool load;
|
||||
if (!bool.Parse(value)) return true;
|
||||
return load;
|
||||
}
|
||||
|
||||
public void ChatLevel(string message) { ChatLevel(message, LevelPermission.Banned); }
|
||||
|
76
Levels/LevelInfo.cs
Normal file
76
Levels/LevelInfo.cs
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
|
||||
|
||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||
not use this file except in compliance with the Licenses. You may
|
||||
obtain a copy of the Licenses at
|
||||
|
||||
http://www.opensource.org/licenses/ecl2.php
|
||||
http://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the Licenses are distributed on an "AS IS"
|
||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
public static class LevelInfo {
|
||||
|
||||
public static Level Find(string name) {
|
||||
name = name.ToLower();
|
||||
Level match = null; int matches = 0;
|
||||
|
||||
foreach (Level level in Server.levels) {
|
||||
if (level.name.ToLower() == name) return level;
|
||||
if (level.name.ToLower().Contains(name)) {
|
||||
match = level; matches++;
|
||||
}
|
||||
}
|
||||
return matches == 1 ? match : null;
|
||||
}
|
||||
|
||||
public static Level FindExact(string name) {
|
||||
name = name.ToLower();
|
||||
|
||||
foreach (Level level in Server.levels) {
|
||||
if (level.name.ToLower() == name) return level;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string FindOfflineProperty(string name, string propKey) {
|
||||
string file = "levels/level properties/" + name + ".properties";
|
||||
if (!File.Exists(file))
|
||||
file = "levels/level properties/" + name;
|
||||
if (!File.Exists(file)) return null;
|
||||
|
||||
string[] lines = null;
|
||||
try {
|
||||
lines = File.ReadAllLines(file);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (string line in lines) {
|
||||
try {
|
||||
if (line == "" || line[0] == '#') continue;
|
||||
int index = line.IndexOf(" = ");
|
||||
if (index == -1) continue;
|
||||
|
||||
string key = line.Substring(0, index).ToLower();
|
||||
if (key == propKey) return line.Substring(index + 3);
|
||||
} catch (Exception e) {
|
||||
Server.ErrorLog(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -407,6 +407,7 @@
|
||||
<Compile Include="Levels\IO\LvlFile.cs" />
|
||||
<Compile Include="Levels\IO\LvlProperties.cs" />
|
||||
<Compile Include="Levels\Level.Blocks.cs" />
|
||||
<Compile Include="Levels\LevelInfo.cs" />
|
||||
<Compile Include="Levels\Physics\AIPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\AirPhysics.cs" />
|
||||
<Compile Include="Levels\Physics\BirdPhysics.cs" />
|
||||
|
@ -173,7 +173,7 @@ namespace MCGalaxy.Util {
|
||||
if (time.AddSeconds(65536).AddSeconds(seconds) < now)
|
||||
return false; // we can safely discard the entire chunk
|
||||
|
||||
lvl = Level.FindExact(chunk.LevelName);
|
||||
lvl = LevelInfo.FindExact(chunk.LevelName);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ namespace MCGalaxy.Util {
|
||||
try {
|
||||
// line format: mapName x y z date oldblock newblock
|
||||
if (!InTime(lines[(i * 7) - 3], seconds)) return false;
|
||||
Level foundLevel = Level.FindExact(lines[(i * 7) - 7]);
|
||||
Level foundLevel = LevelInfo.FindExact(lines[(i * 7) - 7]);
|
||||
if (foundLevel == null) continue;
|
||||
|
||||
Pos.mapName = foundLevel.name;
|
||||
@ -104,7 +104,7 @@ namespace MCGalaxy.Util {
|
||||
try {
|
||||
// line format: mapName x y z date oldblock newblock
|
||||
if (!InTime(lines[(i * 7) - 3], seconds)) return false;
|
||||
Level foundLevel = Level.FindExact(lines[(i * 7) - 7]);
|
||||
Level foundLevel = LevelInfo.FindExact(lines[(i * 7) - 7]);
|
||||
if (foundLevel == null || foundLevel != p.level) continue;
|
||||
|
||||
Pos.mapName = foundLevel.name;
|
||||
|
@ -47,7 +47,7 @@ namespace MCGalaxy {
|
||||
public static void Goto(string waypoint, Player p) {
|
||||
if ( !Exists(waypoint, p) ) return;
|
||||
Waypoint wp = Find(waypoint, p);
|
||||
Level lvl = Level.Find(wp.lvlname);
|
||||
Level lvl = LevelInfo.Find(wp.lvlname);
|
||||
if ( wp == null ) return;
|
||||
if ( lvl != null ) {
|
||||
if ( p.level != lvl ) {
|
||||
|
@ -685,7 +685,7 @@ namespace MCGalaxy
|
||||
if (!key.Equals(mainLevel.name))
|
||||
{
|
||||
Command.all.Find("load").Use(null, key + " " + value);
|
||||
Level l = Level.FindExact(key);
|
||||
Level l = LevelInfo.FindExact(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user