mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 06:43:25 -04:00
Clean up /temprank and /deltemprank, make them work with offline players.
This commit is contained in:
parent
3fc5bb1b75
commit
166e5dfadf
@ -12,6 +12,7 @@ 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.IO;
|
||||
using System.Text;
|
||||
|
||||
@ -23,27 +24,27 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Moderation; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string alltext = File.ReadAllText("text/tempranks.txt");
|
||||
if (!alltext.Contains(message)) {
|
||||
Player.SendMessage(p, "&cPlayer &a" + message + "&c Has not been assigned a temporary rank. Cannot unnasign.");
|
||||
return;
|
||||
bool assigned = false;
|
||||
StringBuilder all = new StringBuilder();
|
||||
Player who = PlayerInfo.Find(message);
|
||||
|
||||
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
|
||||
if (!line.StartsWith(message, comp)) { all.AppendLine(line); continue; }
|
||||
|
||||
string[] parts = line.Split(' ');
|
||||
Group newgroup = Group.Find(parts[2]);
|
||||
Command.all.Find("setrank").Use(null, message + " " + newgroup.name + " temp rank unassigned");
|
||||
Player.SendMessage(p, "&eTemp rank of &a" + message + "&e has been unassigned");
|
||||
if (who != null)
|
||||
Player.SendMessage(who, "&eYour temp rank has been unassigned");
|
||||
assigned = true;
|
||||
}
|
||||
|
||||
StringBuilder all = new StringBuilder();
|
||||
Player who = Player.Find(message);
|
||||
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
|
||||
if (line.Contains(message)) {
|
||||
string group = line.Split(' ')[2];
|
||||
Group newgroup = Group.Find(group);
|
||||
Command.all.Find("setrank").Use(null, message + " " + newgroup.name + " temp rank unassigned");
|
||||
Player.SendMessage(p, "&eTemporary rank of &a" + message + "&e has been unassigned");
|
||||
if (who != null)
|
||||
Player.SendMessage(who, "&eYour temporary rank has been unassigned");
|
||||
} else {
|
||||
all.AppendLine(line);
|
||||
}
|
||||
if (!assigned) {
|
||||
Player.SendMessage(p, "&a" + message + "&c has not been assigned a temp rank."); return;
|
||||
}
|
||||
File.WriteAllText("text/tempranks.txt", all.ToString());
|
||||
}
|
||||
|
@ -24,51 +24,58 @@ namespace MCGalaxy.Commands {
|
||||
public override string type { get { return CommandTypes.Moderation; } }
|
||||
public override bool museumUsable { get { return true; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
string[] args = message.Split(' ');
|
||||
if (args.Length < 3) { Help(p); return; }
|
||||
string player = args[0], rank = args[1], period = args[2];
|
||||
Player who = PlayerInfo.Find(player);
|
||||
if (who == null) { Player.SendMessage(p, "&cPlayer &a" + player + "&c not found."); return; }
|
||||
|
||||
Group newRank = Group.Find(rank);
|
||||
if (newRank == null) {
|
||||
Player.SendMessage(p, "&cRank &a" + rank + "&c does not exist."); return;
|
||||
if (who == null) {
|
||||
OfflinePlayer pInfo = PlayerInfo.FindOffline(player);
|
||||
if (pInfo == null) { Player.SendMessage(p, "&cPlayer &a" + player + "&c not found."); return; }
|
||||
player = pInfo.name;
|
||||
} else {
|
||||
player = who.name;
|
||||
}
|
||||
|
||||
Group group = Group.Find(rank);
|
||||
if (group == null) { Player.SendMessage(p, "&cRank &a" + rank + "&c does not exist."); return; }
|
||||
int periodTime;
|
||||
if (!Int32.TryParse(period, out periodTime)) {
|
||||
Player.SendMessage(p, "&cThe period needs to be a number."); return;
|
||||
}
|
||||
|
||||
string tempRanks = File.ReadAllText("text/tempranks.txt");
|
||||
if (tempRanks.Contains(player)) {
|
||||
Player.SendMessage(p, "&cThe player already has a temporary rank assigned!"); return;
|
||||
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
|
||||
if (line.StartsWith(player, comp)) {
|
||||
Player.SendMessage(p, "&cThe player already has a temporary rank assigned!"); return;
|
||||
}
|
||||
}
|
||||
if (p != null && p == who) {
|
||||
|
||||
if (p != null && who != null && p == who) {
|
||||
Player.SendMessage(p, "&cYou cannot assign yourself a temporary rank."); return;
|
||||
}
|
||||
if (p != null && who.group.Permission >= p.group.Permission) {
|
||||
Group pGroup = who != null ? who.group : Group.findPlayerGroup(player);
|
||||
if (p != null && pGroup.Permission >= p.group.Permission) {
|
||||
Player.SendMessage(p, "Cannot change the temporary rank of someone equal or higher to yourself."); return;
|
||||
}
|
||||
if (p != null && newRank.Permission >= p.group.Permission) {
|
||||
if (p != null && group.Permission >= p.group.Permission) {
|
||||
Player.SendMessage(p, "Cannot change the temporary rank to a higher rank than yourself."); return;
|
||||
}
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
string oldrank = who.group.name;
|
||||
string assigner = p == null ? "Console" : p.name;
|
||||
using (StreamWriter sw = new StreamWriter("text/tempranks.txt", true))
|
||||
sw.WriteLine(who.name + " " + rank + " " + oldrank + " " + period + " " + now.Minute + " " +
|
||||
sw.WriteLine(player + " " + rank + " " + pGroup.name + " " + period + " " + now.Minute + " " +
|
||||
now.Hour + " " + now.Day + " " + now.Month + " " + now.Year + " " + assigner);
|
||||
|
||||
Command.all.Find("setrank").Use(null, who.name + " " + newRank.name + " assigning temp rank");
|
||||
Command.all.Find("setrank").Use(null, who.name + " " + group.name + " assigning temp rank");
|
||||
Player.SendMessage(p, "Temporary rank (" + rank + ") assigned succesfully to " + player + " for " + period + " hours");
|
||||
Player.SendMessage(who, "Your Temporary rank (" + rank + ") is assigned succesfully for " + period + " hours");
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.SendMessage(p, "/temprank <player> <rank> <period(hours)> - Sets a temporary rank for the specified player.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -213,9 +213,9 @@ namespace MCGalaxy {
|
||||
Server.s.Log("Iterations = " + numIterations);
|
||||
|
||||
for (int iter = 0; iter < numIterations; iter++) {
|
||||
float theta = (float)(rand.NextDouble() * 360);
|
||||
float cosPhi = (float)Math.Cos(theta);
|
||||
float sinPhi = (float)Math.Sin(theta);
|
||||
float phi = (float)(rand.NextDouble() * 360);
|
||||
float cosPhi = (float)Math.Cos(phi);
|
||||
float sinPhi = (float)Math.Sin(phi);
|
||||
float c = ((float)rand.NextDouble()) * 2 * d - d;
|
||||
|
||||
int index = 0;
|
||||
|
@ -16,10 +16,11 @@ permiusing MCGalaxy;ssions and limitations under the Licenses.
|
||||
using System.IO;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
|
||||
public static class Checktimer {
|
||||
|
||||
|
||||
static System.Timers.Timer t;
|
||||
const StringComparison comp = StringComparison.OrdinalIgnoreCase;
|
||||
public static void StartTimer() {
|
||||
t = new System.Timers.Timer();
|
||||
t.AutoReset = false;
|
||||
@ -40,10 +41,10 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
public static void TRExpiryCheck() {
|
||||
Player[] players = PlayerInfo.Online;
|
||||
Player[] players = PlayerInfo.Online;
|
||||
foreach (Player p in players) {
|
||||
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
|
||||
if (!line.Contains(p.name)) continue;
|
||||
if (line.IndexOf(p.name, comp) < 0) continue;
|
||||
string[] args = line.Split(' ');
|
||||
|
||||
int period = Convert.ToInt32(args[3]);
|
||||
@ -55,7 +56,7 @@ namespace MCGalaxy {
|
||||
|
||||
Player who = PlayerInfo.Find(args[0]);
|
||||
DateTime expire = new DateTime(years, months, days, hours, minutes, 0)
|
||||
.AddHours(Convert.ToDouble(period));
|
||||
.AddHours(Convert.ToDouble(period));
|
||||
if (DateTime.Now >= expire)
|
||||
Command.all.Find("deltemprank").Use(null, who.name);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user