Using /help colors now shows custom colour codes, also condense down /help colors. Make /temprank and various other temprank related code 59.48% nicer.

This commit is contained in:
UnknownShadow200 2016-02-24 22:28:13 +11:00
parent 5aef35730c
commit c0be192333
6 changed files with 104 additions and 200 deletions

View File

@ -41,7 +41,7 @@ namespace MCGalaxy.Commands {
case "delete": case "delete":
RemoveHandler(p, args); break; RemoveHandler(p, args); break;
case "list": case "list":
ListHandler(p, args); break; ListHandler(p, args, false); break;
default: default:
Help(p); break; Help(p); break;
} }
@ -112,9 +112,9 @@ namespace MCGalaxy.Commands {
Player.SendMessage(p, "Successfully removed a custom color."); Player.SendMessage(p, "Successfully removed a custom color.");
} }
void ListHandler(Player p, string[] args) { internal static void ListHandler(Player p, string[] args, bool all) {
int offset = 0, index = 0, count = 0; int offset = 0, index = 0, count = 0;
if (args.Length > 1) int.TryParse(args[1], out offset); if (args != null && args.Length > 1) int.TryParse(args[1], out offset);
CustomColor[] cols = Colors.ExtColors; CustomColor[] cols = Colors.ExtColors;
for( int i = 0; i < cols.Length; i++ ) { for( int i = 0; i < cols.Length; i++ ) {
@ -126,7 +126,7 @@ namespace MCGalaxy.Commands {
const string format = "{0} - %{1} displays as &{1}{2}{4}, and falls back to {3}."; const string format = "{0} - %{1} displays as &{1}{2}{4}, and falls back to {3}.";
Player.SendMessage(p, String.Format(format, col.Name, col.Code, Hex(col), col.Fallback, Server.DefaultColor), false); Player.SendMessage(p, String.Format(format, col.Name, col.Code, Hex(col), col.Fallback, Server.DefaultColor), false);
if (count >= 8) { if (count >= 8 && !all) {
const string helpFormat = "To see the next set of custom colors, type %T/ccols list {0}"; const string helpFormat = "To see the next set of custom colors, type %T/ccols list {0}";
Player.SendMessage(p, String.Format(helpFormat, offset + 8)); Player.SendMessage(p, String.Format(helpFormat, offset + 8));
return; return;

View File

@ -103,16 +103,13 @@ namespace MCGalaxy.Commands
break; break;
case "colours": case "colours":
case "colors": case "colors":
Player.SendMessage(p, "&fTo use a color simply put a '%' sign symbol before you put the color code."); Player.SendMessage(p, "&fTo use a color, put a '%' and then put the color code.");
Player.SendMessage(p, "Colors Available:"); Player.SendMessage(p, "Colors Available:");
Player.SendMessage(p, "0 - &0Black %S| 8 - &8Gray"); Player.SendMessage(p, "0 - &0Black %S| 1 - &1Navy %S| 2 - &2Green %S| 3 - &3Teal");
Player.SendMessage(p, "1 - &1Navy %S| 9 - &9Blue"); Player.SendMessage(p, "4 - &4Maroon %S| 5 - &5Purple %S| 6 - &6Gold %S| 7 - &7Silver");
Player.SendMessage(p, "2 - &2Green %S| a - &aLime"); Player.SendMessage(p, "8 - &8Gray %S| 9 - &9Blue %S| a - &aLime %S| b - &bAqua");
Player.SendMessage(p, "3 - &3Teal %S| b - &bAqua"); Player.SendMessage(p, "c - &cRed %S| d - &dPink %S| e - &eYellow %S| f - &fWhite");
Player.SendMessage(p, "4 - &4Maroon %S| c - &cRed"); CmdCustomColors.ListHandler(p, null, true);
Player.SendMessage(p, "5 - &5Purple %S| d - &dPink");
Player.SendMessage(p, "6 - &6Gold %S| e - &eYellow");
Player.SendMessage(p, "7 - &7Silver %S| f - &fWhite");
break; break;
case "old": case "old":
case "oldmenu": case "oldmenu":

View File

@ -40,7 +40,7 @@ namespace MCGalaxy.Commands
{ {
string group = line.Split(' ')[2]; string group = line.Split(' ')[2];
Group newgroup = Group.Find(group); Group newgroup = Group.Find(group);
Command.all.Find("setrank").Use(null, who.name + " " + newgroup.name); Command.all.Find("setrank").Use(null, who.name + " " + newgroup.name + " temp rank unassigned");
Player.SendMessage(p, "&eTemporary rank of &a" + message + "&e has been unassigned"); Player.SendMessage(p, "&eTemporary rank of &a" + message + "&e has been unassigned");
Player.SendMessage(who, "&eYour temporary rank has been unassigned"); Player.SendMessage(who, "&eYour temporary rank has been unassigned");
} }

View File

@ -11,146 +11,64 @@ software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
using System; using System;
using System.IO; using System.IO;
namespace MCGalaxy.Commands
{ namespace MCGalaxy.Commands {
public sealed class CmdTempRank : Command
{ public sealed class CmdTempRank : Command {
public override string name { get { return "temprank"; } } public override string name { get { return "temprank"; } }
public override string shortcut { get { return "tr"; } } public override string shortcut { get { return "tr"; } }
public override string type { get { return CommandTypes.Moderation; } } public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdTempRank() { }
public override void Use(Player p, string message)
{
string player = "", rank = "", period = "";
try
{
player = message.Split(' ')[0];
rank = message.Split(' ')[1];
period = message.Split(' ')[2];
}
catch
{
Help(p);
}
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); Player who = PlayerInfo.Find(player);
if (who == null) { Player.SendMessage(p, "&cPlayer &a" + player + "&c not found."); return; }
Group newRank = Group.Find(rank);
if (player == "") { Player.SendMessage(p, "&cYou have to enter a player!"); return; } if (newRank == null) {
if (who == null) { Player.SendMessage(p, "&cPlayer &a" + player + "&c not found!"); return; } Player.SendMessage(p, "&cRank &a" + rank + "&c does not exist."); return;
if (rank == "") { Player.SendMessage(p, "&cYou have to enter a rank!"); return; }
else
{
Group groupNew = Group.Find(rank);
if (groupNew == null)
{
Player.SendMessage(p, "&cRank &a" + rank + "&c does not exist");
return;
}
} }
if (period == "") { Player.SendMessage(p, "&cYou have to enter a time period!"); return; } int periodTime;
Boolean isnumber = true; if (!Int32.TryParse(period, out periodTime)) {
try Player.SendMessage(p, "&cThe period needs to be a number."); return;
{
Convert.ToInt32(period);
}
catch
{
isnumber = false;
}
if (!isnumber)
{
Player.SendMessage(p, "&cThe period needs to be a number!");
return;
} }
string alltext = File.ReadAllText("text/tempranks.txt"); string tempRanks = File.ReadAllText("text/tempranks.txt");
if (alltext.Contains(player)) if (tempRanks.Contains(player)) {
{ Player.SendMessage(p, "&cThe player already has a temporary rank assigned!"); return;
Player.SendMessage(p, "&cThe player already has a temporary rank assigned!");
return;
} }
bool byconsole; if (p != null && p == who) {
if (p == null) Player.SendMessage(p, "&cYou cannot assign yourself a temporary rank."); return;
{
byconsole = true;
goto skipper;
} }
else if (p != null && who.group.Permission >= p.group.Permission) {
{ Player.SendMessage(p, "Cannot change the temporary rank of someone equal or higher to yourself."); return;
byconsole = false;
} }
if (player == p.name) if (p != null && newRank.Permission >= p.group.Permission) {
{ Player.SendMessage(p, "Cannot change the temporary rank to a higher rank than yourself."); return;
Player.SendMessage(p, "&cYou cannot assign yourself a temporary rank!");
return;
} }
Player who3 = PlayerInfo.Find(player);
if (who3.group.Permission >= p.group.Permission) DateTime now = DateTime.Now;
{
Player.SendMessage(p, "Cannot change the temporary rank of someone equal or higher to yourself.");
return;
}
Group newRank2 = Group.Find(rank);
if (newRank2.Permission >= p.group.Permission)
{
Player.SendMessage(p, "Cannot change the temporary rank to a higher rank than yourself");
return;
}
skipper:
string year = DateTime.Now.Year.ToString();
string month = DateTime.Now.Month.ToString();
string day = DateTime.Now.Day.ToString();
string hour = DateTime.Now.Hour.ToString();
string minute = DateTime.Now.Minute.ToString();
string oldrank = who.group.name; string oldrank = who.group.name;
string assigner; string assigner = p == null ? "Console" : p.name;
if (byconsole) using (StreamWriter sw = new StreamWriter("text/tempranks.txt", true))
{ sw.WriteLine(who.name + " " + rank + " " + oldrank + " " + period + " " + now.Minute + " " +
assigner = "Console"; now.Hour + " " + now.Day + " " + now.Month + " " + now.Year + " " + assigner);
}
else {
assigner = p.name;
}
Boolean tryer = true;
try
{
StreamWriter sw;
sw = File.AppendText("text/tempranks.txt");
sw.WriteLine(who.name + " " + rank + " " + oldrank + " " + period + " " + minute + " " + hour + " " + day + " " + month + " " + year + " " + assigner);
sw.Close();
}
catch
{
tryer = false;
}
if (!tryer)
{
Player.SendMessage(p, "&cAn error occurred!");
}
else
{
Group newgroup = Group.Find(rank);
Command.all.Find("setrank").Use(null, who.name + " " + newgroup.name);
Player.SendMessage(p, "Temporary rank (" + rank + ") is assigned succesfully to " + player + " for " + period + " hours");
Player who2 = PlayerInfo.Find(player);
Player.SendMessage(who2, "Your Temporary rank (" + rank + ") is assigned succesfully for " + period + " hours");
}
Command.all.Find("setrank").Use(null, who.name + " " + newRank.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)
{ public override void Help(Player p) {
Player.SendMessage(p, "/temprank <player> <rank> <period(hours)> - Sets a temporary rank for the specified player."); Player.SendMessage(p, "/temprank <player> <rank> <period(hours)> - Sets a temporary rank for the specified player.");
} }
} }
} }

View File

@ -40,28 +40,28 @@ namespace MCGalaxy.Commands
return; return;
} }
foreach (string line3 in File.ReadAllLines("text/tempranks.txt")) foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
{ if (!line.Contains(message)) continue;
if (line3.Contains(message))
{ string[] args = line.Split(' ');
string temprank = line3.Split(' ')[1]; string temprank = args[1];
string oldrank = line3.Split(' ')[2]; string oldrank = args[2];
string tempranker = line3.Split(' ')[9]; string tempranker = args[9];
int period = Convert.ToInt32(line3.Split(' ')[3]); int period = Convert.ToInt32(args[3]);
int minutes = Convert.ToInt32(line3.Split(' ')[4]); int minutes = Convert.ToInt32(args[4]);
int hours = Convert.ToInt32(line3.Split(' ')[5]); int hours = Convert.ToInt32(args[5]);
int days = Convert.ToInt32(line3.Split(' ')[6]); int days = Convert.ToInt32(args[6]);
int months = Convert.ToInt32(line3.Split(' ')[7]); int months = Convert.ToInt32(args[7]);
int years = Convert.ToInt32(line3.Split(' ')[8]); int years = Convert.ToInt32(args[8]);
DateTime ExpireDate = new DateTime(years, months, days, hours, minutes, 0);
DateTime tocheck = ExpireDate.AddHours(Convert.ToDouble(period)); DateTime assignmentDate = new DateTime(years, months, days, hours, minutes, 0);
Player.SendMessage(p, "&1Temporary Rank Information of " + message); DateTime expireDate = assignmentDate.AddHours(Convert.ToDouble(period));
Player.SendMessage(p, "&aTemporary Rank: " + temprank); Player.SendMessage(p, "&1Temporary Rank Information of " + message);
Player.SendMessage(p, "&aOld Rank: " + oldrank); Player.SendMessage(p, "&aTemporary Rank: " + temprank);
Player.SendMessage(p, "&aDate of assignment: " + ExpireDate.ToString()); Player.SendMessage(p, "&aOld Rank: " + oldrank);
Player.SendMessage(p, "&aDate of expiry: " + tocheck.ToString()); Player.SendMessage(p, "&aDate of assignment: " + assignmentDate.ToString());
Player.SendMessage(p, "&aTempranked by: " + tempranker); Player.SendMessage(p, "&aDate of expiry: " + expireDate.ToString());
} Player.SendMessage(p, "&aTempranked by: " + tempranker);
} }
} }

View File

@ -11,63 +11,52 @@ software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permiusing MCGalaxy;ssions and limitations under the Licenses. permiusing MCGalaxy;ssions and limitations under the Licenses.
*/ */
using System; using System;
using System.IO; using System.IO;
namespace MCGalaxy
{ namespace MCGalaxy {
public static class Checktimer
{ public static class Checktimer {
static System.Timers.Timer t; static System.Timers.Timer t;
public static void StartTimer() public static void StartTimer() {
{
t = new System.Timers.Timer(); t = new System.Timers.Timer();
t.AutoReset = false; t.AutoReset = false;
t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed); t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
t.Interval = GetInterval(); t.Interval = GetInterval();
t.Start(); t.Start();
} }
static double GetInterval()
{ static double GetInterval() {
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
return ((60 - now.Second) * 1000 - now.Millisecond); return ((60 - now.Second) * 1000 - now.Millisecond);
} }
/// <summary>
/// Put methods to make them execute every 60 seconds static void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
/// </summary>
/// <param name="sender">For the timer</param>
/// <param name="e">For the timer</param>
static void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
t.Interval = GetInterval(); t.Interval = GetInterval();
t.Start(); t.Start();
TRExpiryCheck(); // every 60 seconds
// methods to be executed every 60 seconds!:
TRExpiryCheck();
} }
public static void TRExpiryCheck()
{ public static void TRExpiryCheck() {
foreach (Player p in PlayerInfo.players) foreach (Player p in PlayerInfo.players) {
{ foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
foreach (string line3 in File.ReadAllLines("text/tempranks.txt")) if (!line.Contains(p.name)) continue;
{ string[] args = line.Split(' ');
if (line3.Contains(p.name))
{ int period = Convert.ToInt32(args[3]);
string player = line3.Split(' ')[0]; int minutes = Convert.ToInt32(args[4]);
int period = Convert.ToInt32(line3.Split(' ')[3]); int hours = Convert.ToInt32(args[5]);
int minutes = Convert.ToInt32(line3.Split(' ')[4]); int days = Convert.ToInt32(args[6]);
int hours = Convert.ToInt32(line3.Split(' ')[5]); int months = Convert.ToInt32(args[7]);
int days = Convert.ToInt32(line3.Split(' ')[6]); int years = Convert.ToInt32(args[8]);
int months = Convert.ToInt32(line3.Split(' ')[7]);
int years = Convert.ToInt32(line3.Split(' ')[8]); Player who = PlayerInfo.Find(args[0]);
Player who = PlayerInfo.Find(player); DateTime expire = new DateTime(years, months, days, hours, minutes, 0)
DateTime ExpireDate = new DateTime(years, months, days, hours, minutes, 0); .AddHours(Convert.ToDouble(period));
DateTime tocheck = ExpireDate.AddHours(Convert.ToDouble(period)); if (DateTime.Now >= expire)
DateTime tochecknow = DateTime.Now; Command.all.Find("deltemprank").Use(null, who.name);
double datecompare = DateTime.Compare(tocheck, tochecknow);
if (datecompare <= 0)
Command.all.Find("deltemprank").Use(null, who.name);
}
} }
} }
} }