mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 14:54:12 -04:00
Persist custom set skins and models (Thanks goodlyay), closes #142.
This commit is contained in:
parent
0258839aae
commit
9eaa14593a
@ -57,24 +57,20 @@ namespace MCGalaxy.Commands {
|
||||
if (who == null) { Player.SendMessage(p, "Console must provide a player name."); return; }
|
||||
model = message;
|
||||
}
|
||||
model = model.ToLower();
|
||||
|
||||
if (isBot) {
|
||||
pBot.model = model;
|
||||
UpdateModel(pBot.id, model, pBot.level, null);
|
||||
Entities.UpdateModel(pBot.id, model, pBot.level, null);
|
||||
Player.GlobalMessage("Bot " + pBot.name + "'s %Smodel was changed to a &c" + model);
|
||||
} else {
|
||||
who.model = model;
|
||||
UpdateModel(who.id, model, who.level, who);
|
||||
Entities.UpdateModel(who.id, model, who.level, who);
|
||||
Player.GlobalMessage(who.ColoredName + "'s %Smodel was changed to a &c" + model);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateModel(byte id, string model, Level level, Player who) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != level || !pl.HasCpeExt(CpeExt.ChangeModel)) continue;
|
||||
byte sendId = (pl == who) ? (byte)0xFF : id;
|
||||
pl.SendChangeModel(sendId, model);
|
||||
Server.Models.DeleteStartsWith(who.name + " ");
|
||||
if (model != "humanoid")
|
||||
Server.Models.Append(who.name + " " + model);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +92,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
if (p == null) { MessageInGameOnly(p); }
|
||||
string model = message == "" ? "normal" : message;
|
||||
string model = message == "" ? "humanoid" : message;
|
||||
Command.all.Find("model").Use(p, p.name + " " + model);
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,10 @@ namespace MCGalaxy.Commands {
|
||||
Entities.GlobalDespawn(who, true);
|
||||
Entities.GlobalSpawn(who, true);
|
||||
Player.GlobalMessage(who.ColoredName + "'s %Sskin was changed to &c" + skin);
|
||||
|
||||
Server.Skins.DeleteStartsWith(who.name + " ");
|
||||
if (skin != who.truename)
|
||||
Server.Skins.Append(who.name + " " + skin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,12 +48,12 @@ namespace MCGalaxy.Commands
|
||||
Entities.GlobalSpawn(who, (ushort)who.level.jailx, (ushort)who.level.jaily, (ushort)who.level.jailz,
|
||||
who.level.jailrotx, who.level.jailroty, true);
|
||||
|
||||
Server.Jailed.DeleteWord(who.name.ToLower());
|
||||
Server.Jailed.DeleteContains(who.name.ToLower());
|
||||
Server.Jailed.Append(who.name.ToLower() + " " + who.level.name);
|
||||
Player.SendChatFrom(who, who.ColoredName + " %Swas &8jailed", false);
|
||||
Player.AddNote(who.name, p, "J");
|
||||
} else {
|
||||
Server.Jailed.DeleteWord(who.name.ToLower());
|
||||
Server.Jailed.DeleteContains(who.name.ToLower());
|
||||
who.jailed = false;
|
||||
Command.all.Find("spawn").Use(who, "");
|
||||
Player.SendMessage(p, "You freed " + who.name + " from jail");
|
||||
|
@ -37,7 +37,7 @@ namespace MCGalaxy.Commands
|
||||
if (Server.muted.Contains(message)) {
|
||||
Server.muted.Remove(message);
|
||||
Player.GlobalMessage(message + Server.DefaultColor + " is not online but is now &bun-muted");
|
||||
Server.Muted.DeleteWord(who.name.ToLower());
|
||||
Server.Muted.DeleteContains(who.name.ToLower());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands
|
||||
if (who.muted) {
|
||||
who.muted = false;
|
||||
Player.SendChatFrom(who, who.color + who.DisplayName + " %Shas been &bun-muted", false);
|
||||
Server.Muted.DeleteWord(who.name.ToLower());
|
||||
Server.Muted.DeleteContains(who.name.ToLower());
|
||||
} else {
|
||||
if (p != null && who.group.Permission >= p.group.Permission) {
|
||||
MessageTooHighRank(p, "mute", false); return;
|
||||
|
@ -132,6 +132,17 @@ namespace MCGalaxy {
|
||||
return p.group.Permission >= who.group.Permission;
|
||||
}
|
||||
|
||||
/// <summary> Updates the model of the entity with the specified id to all other players. </summary>
|
||||
public static void UpdateModel(byte id, string model, Level lvl, Player who) {
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
foreach (Player pl in players) {
|
||||
if (pl.level != lvl || !pl.HasCpeExt(CpeExt.ChangeModel)) continue;
|
||||
if (who != null && !CanSeeEntity(pl, who)) continue;
|
||||
|
||||
byte sendId = (pl.id == id) ? (byte)0xFF : id;
|
||||
pl.SendChangeModel(sendId, model);
|
||||
}
|
||||
}
|
||||
|
||||
#region Position updates
|
||||
|
||||
|
@ -306,7 +306,6 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
DisplayName = name;
|
||||
SkinName = name;
|
||||
name += "+";
|
||||
byte type = message[129];
|
||||
|
||||
@ -515,6 +514,7 @@ namespace MCGalaxy {
|
||||
Game.Team = Team.FindTeam(this);
|
||||
SetPrefix();
|
||||
playerDb.Dispose();
|
||||
LoadCpeData();
|
||||
|
||||
if (Server.verifyadmins && group.Permission >= Server.verifyadminsrank)
|
||||
adminpen = true;
|
||||
@ -589,6 +589,28 @@ namespace MCGalaxy {
|
||||
Loading = false;
|
||||
}
|
||||
|
||||
void LoadCpeData() {
|
||||
try {
|
||||
foreach (string line in Server.Skins.Find(name)) {
|
||||
string[] parts = line.Split(trimChars, 2);
|
||||
if (parts.Length == 1) continue;
|
||||
skinName = parts[1];
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Server.ErrorLog(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
foreach (string line in Server.Models.Find(name)) {
|
||||
string[] parts = line.Split(trimChars, 2);
|
||||
if (parts.Length == 1) continue;
|
||||
model = parts[1];
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Server.ErrorLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckOutdatedClient() {
|
||||
if (appName == null || !appName.StartsWith("ClassicalSharp ")) return;
|
||||
int spaceIndex = appName.IndexOf(' ');
|
||||
|
@ -78,7 +78,6 @@ namespace MCGalaxy {
|
||||
public TimeSpan time;
|
||||
public string name;
|
||||
public string DisplayName;
|
||||
public string SkinName;
|
||||
public string realName;
|
||||
public int warn = 0;
|
||||
public byte id;
|
||||
|
@ -32,7 +32,7 @@ namespace MCGalaxy {
|
||||
locker = new object();
|
||||
}
|
||||
|
||||
/// <summary> Finds all lines which start with the given name. </summary>
|
||||
/// <summary> Finds all lines which caselessly start with the given name. </summary>
|
||||
public IEnumerable<string> Find(string name) {
|
||||
if (!File.Exists(file)) yield break;
|
||||
|
||||
@ -45,17 +45,35 @@ namespace MCGalaxy {
|
||||
yield break;
|
||||
}
|
||||
|
||||
/// <summary> Deletes all lines which contain the given word. </summary>
|
||||
public void DeleteWord(string word) {
|
||||
/// <summary> Deletes all lines which start with the given value. </summary>
|
||||
public void DeleteStartsWith(string value) {
|
||||
if (!File.Exists(file)) return;
|
||||
List<string> lines = new List<string>();
|
||||
using (StreamReader r = new StreamReader(file)) {
|
||||
string line;
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
if (line.Contains(word)) continue;
|
||||
if (line.StartsWith(value)) continue;
|
||||
lines.Add(line);
|
||||
}
|
||||
}
|
||||
WriteLines(lines);
|
||||
}
|
||||
|
||||
/// <summary> Deletes all lines which contain the given value. </summary>
|
||||
public void DeleteContains(string value) {
|
||||
if (!File.Exists(file)) return;
|
||||
List<string> lines = new List<string>();
|
||||
using (StreamReader r = new StreamReader(file)) {
|
||||
string line;
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
if (line.Contains(value)) continue;
|
||||
lines.Add(line);
|
||||
}
|
||||
}
|
||||
WriteLines(lines);
|
||||
}
|
||||
|
||||
void WriteLines(List<string> lines) {
|
||||
lock (locker) {
|
||||
using (StreamWriter w = new StreamWriter(file, false)) {
|
||||
foreach (string line in lines)
|
||||
|
@ -81,6 +81,8 @@ namespace MCGalaxy
|
||||
public static PlayersFile Jailed = new PlayersFile("ranks/jailed.txt");
|
||||
public static PlayersFile TempRanks = new PlayersFile("text/tempranks.txt");
|
||||
public static PlayersFile Notes = new PlayersFile("text/notes.txt");
|
||||
public static PlayersFile Skins = new PlayersFile("extra/skins.txt");
|
||||
public static PlayersFile Models = new PlayersFile("extra/models.txt");
|
||||
public static Version Version { get { return System.Reflection.Assembly.GetAssembly(typeof(Server)).GetName().Version; } }
|
||||
|
||||
public static string VersionString {
|
||||
|
Loading…
x
Reference in New Issue
Block a user