mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 22:30:52 -04:00
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:
parent
5aef35730c
commit
c0be192333
@ -41,7 +41,7 @@ namespace MCGalaxy.Commands {
|
||||
case "delete":
|
||||
RemoveHandler(p, args); break;
|
||||
case "list":
|
||||
ListHandler(p, args); break;
|
||||
ListHandler(p, args, false); break;
|
||||
default:
|
||||
Help(p); break;
|
||||
}
|
||||
@ -112,9 +112,9 @@ namespace MCGalaxy.Commands {
|
||||
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;
|
||||
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;
|
||||
|
||||
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}.";
|
||||
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}";
|
||||
Player.SendMessage(p, String.Format(helpFormat, offset + 8));
|
||||
return;
|
||||
|
@ -103,16 +103,13 @@ namespace MCGalaxy.Commands
|
||||
break;
|
||||
case "colours":
|
||||
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, "0 - &0Black %S| 8 - &8Gray");
|
||||
Player.SendMessage(p, "1 - &1Navy %S| 9 - &9Blue");
|
||||
Player.SendMessage(p, "2 - &2Green %S| a - &aLime");
|
||||
Player.SendMessage(p, "3 - &3Teal %S| b - &bAqua");
|
||||
Player.SendMessage(p, "4 - &4Maroon %S| c - &cRed");
|
||||
Player.SendMessage(p, "5 - &5Purple %S| d - &dPink");
|
||||
Player.SendMessage(p, "6 - &6Gold %S| e - &eYellow");
|
||||
Player.SendMessage(p, "7 - &7Silver %S| f - &fWhite");
|
||||
Player.SendMessage(p, "0 - &0Black %S| 1 - &1Navy %S| 2 - &2Green %S| 3 - &3Teal");
|
||||
Player.SendMessage(p, "4 - &4Maroon %S| 5 - &5Purple %S| 6 - &6Gold %S| 7 - &7Silver");
|
||||
Player.SendMessage(p, "8 - &8Gray %S| 9 - &9Blue %S| a - &aLime %S| b - &bAqua");
|
||||
Player.SendMessage(p, "c - &cRed %S| d - &dPink %S| e - &eYellow %S| f - &fWhite");
|
||||
CmdCustomColors.ListHandler(p, null, true);
|
||||
break;
|
||||
case "old":
|
||||
case "oldmenu":
|
||||
|
@ -40,7 +40,7 @@ namespace MCGalaxy.Commands
|
||||
{
|
||||
string group = line.Split(' ')[2];
|
||||
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(who, "&eYour temporary rank has been unassigned");
|
||||
}
|
||||
|
@ -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
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
namespace MCGalaxy.Commands
|
||||
{
|
||||
public sealed class CmdTempRank : Command
|
||||
{
|
||||
|
||||
namespace MCGalaxy.Commands {
|
||||
|
||||
public sealed class CmdTempRank : Command {
|
||||
|
||||
public override string name { get { return "temprank"; } }
|
||||
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 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);
|
||||
if (who == null) { Player.SendMessage(p, "&cPlayer &a" + player + "&c not found."); return; }
|
||||
|
||||
|
||||
if (player == "") { Player.SendMessage(p, "&cYou have to enter a player!"); return; }
|
||||
if (who == null) { Player.SendMessage(p, "&cPlayer &a" + player + "&c not found!"); 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;
|
||||
}
|
||||
Group newRank = Group.Find(rank);
|
||||
if (newRank == 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; }
|
||||
Boolean isnumber = true;
|
||||
try
|
||||
{
|
||||
Convert.ToInt32(period);
|
||||
}
|
||||
catch
|
||||
{
|
||||
isnumber = false;
|
||||
}
|
||||
if (!isnumber)
|
||||
{
|
||||
Player.SendMessage(p, "&cThe period needs to be a number!");
|
||||
return;
|
||||
int periodTime;
|
||||
if (!Int32.TryParse(period, out periodTime)) {
|
||||
Player.SendMessage(p, "&cThe period needs to be a number."); return;
|
||||
}
|
||||
|
||||
string alltext = File.ReadAllText("text/tempranks.txt");
|
||||
if (alltext.Contains(player))
|
||||
{
|
||||
Player.SendMessage(p, "&cThe player already has a temporary rank assigned!");
|
||||
return;
|
||||
string tempRanks = File.ReadAllText("text/tempranks.txt");
|
||||
if (tempRanks.Contains(player)) {
|
||||
Player.SendMessage(p, "&cThe player already has a temporary rank assigned!"); return;
|
||||
}
|
||||
bool byconsole;
|
||||
if (p == null)
|
||||
{
|
||||
byconsole = true;
|
||||
goto skipper;
|
||||
if (p != null && p == who) {
|
||||
Player.SendMessage(p, "&cYou cannot assign yourself a temporary rank."); return;
|
||||
}
|
||||
else
|
||||
{
|
||||
byconsole = false;
|
||||
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;
|
||||
}
|
||||
if (player == p.name)
|
||||
{
|
||||
Player.SendMessage(p, "&cYou cannot assign yourself a temporary rank!");
|
||||
return;
|
||||
if (p != null && newRank.Permission >= p.group.Permission) {
|
||||
Player.SendMessage(p, "Cannot change the temporary rank to a higher rank than yourself."); return;
|
||||
}
|
||||
Player who3 = PlayerInfo.Find(player);
|
||||
if (who3.group.Permission >= p.group.Permission)
|
||||
{
|
||||
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();
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
string oldrank = who.group.name;
|
||||
string assigner;
|
||||
if (byconsole)
|
||||
{
|
||||
assigner = "Console";
|
||||
}
|
||||
else {
|
||||
assigner = p.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 + " " +
|
||||
now.Hour + " " + now.Day + " " + now.Month + " " + now.Year + " " + assigner);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,28 +40,28 @@ namespace MCGalaxy.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string line3 in File.ReadAllLines("text/tempranks.txt"))
|
||||
{
|
||||
if (line3.Contains(message))
|
||||
{
|
||||
string temprank = line3.Split(' ')[1];
|
||||
string oldrank = line3.Split(' ')[2];
|
||||
string tempranker = line3.Split(' ')[9];
|
||||
int period = Convert.ToInt32(line3.Split(' ')[3]);
|
||||
int minutes = Convert.ToInt32(line3.Split(' ')[4]);
|
||||
int hours = Convert.ToInt32(line3.Split(' ')[5]);
|
||||
int days = Convert.ToInt32(line3.Split(' ')[6]);
|
||||
int months = Convert.ToInt32(line3.Split(' ')[7]);
|
||||
int years = Convert.ToInt32(line3.Split(' ')[8]);
|
||||
DateTime ExpireDate = new DateTime(years, months, days, hours, minutes, 0);
|
||||
DateTime tocheck = ExpireDate.AddHours(Convert.ToDouble(period));
|
||||
Player.SendMessage(p, "&1Temporary Rank Information of " + message);
|
||||
Player.SendMessage(p, "&aTemporary Rank: " + temprank);
|
||||
Player.SendMessage(p, "&aOld Rank: " + oldrank);
|
||||
Player.SendMessage(p, "&aDate of assignment: " + ExpireDate.ToString());
|
||||
Player.SendMessage(p, "&aDate of expiry: " + tocheck.ToString());
|
||||
Player.SendMessage(p, "&aTempranked by: " + tempranker);
|
||||
}
|
||||
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
|
||||
if (!line.Contains(message)) continue;
|
||||
|
||||
string[] args = line.Split(' ');
|
||||
string temprank = args[1];
|
||||
string oldrank = args[2];
|
||||
string tempranker = args[9];
|
||||
int period = Convert.ToInt32(args[3]);
|
||||
int minutes = Convert.ToInt32(args[4]);
|
||||
int hours = Convert.ToInt32(args[5]);
|
||||
int days = Convert.ToInt32(args[6]);
|
||||
int months = Convert.ToInt32(args[7]);
|
||||
int years = Convert.ToInt32(args[8]);
|
||||
|
||||
DateTime assignmentDate = new DateTime(years, months, days, hours, minutes, 0);
|
||||
DateTime expireDate = assignmentDate.AddHours(Convert.ToDouble(period));
|
||||
Player.SendMessage(p, "&1Temporary Rank Information of " + message);
|
||||
Player.SendMessage(p, "&aTemporary Rank: " + temprank);
|
||||
Player.SendMessage(p, "&aOld Rank: " + oldrank);
|
||||
Player.SendMessage(p, "&aDate of assignment: " + assignmentDate.ToString());
|
||||
Player.SendMessage(p, "&aDate of expiry: " + expireDate.ToString());
|
||||
Player.SendMessage(p, "&aTempranked by: " + tempranker);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
or implied. See the Licenses for the specific language governing
|
||||
permiusing MCGalaxy;ssions and limitations under the Licenses.
|
||||
*/
|
||||
*/
|
||||
using System;
|
||||
using System.IO;
|
||||
namespace MCGalaxy
|
||||
{
|
||||
public static class Checktimer
|
||||
{
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
public static class Checktimer {
|
||||
|
||||
static System.Timers.Timer t;
|
||||
public static void StartTimer()
|
||||
{
|
||||
public static void StartTimer() {
|
||||
t = new System.Timers.Timer();
|
||||
t.AutoReset = false;
|
||||
t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
|
||||
t.Interval = GetInterval();
|
||||
t.Start();
|
||||
}
|
||||
static double GetInterval()
|
||||
{
|
||||
|
||||
static double GetInterval() {
|
||||
DateTime now = DateTime.Now;
|
||||
return ((60 - now.Second) * 1000 - now.Millisecond);
|
||||
}
|
||||
/// <summary>
|
||||
/// Put methods to make them execute every 60 seconds
|
||||
/// </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)
|
||||
{
|
||||
|
||||
static void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
|
||||
t.Interval = GetInterval();
|
||||
t.Start();
|
||||
|
||||
// methods to be executed every 60 seconds!:
|
||||
TRExpiryCheck();
|
||||
TRExpiryCheck(); // every 60 seconds
|
||||
}
|
||||
public static void TRExpiryCheck()
|
||||
{
|
||||
foreach (Player p in PlayerInfo.players)
|
||||
{
|
||||
foreach (string line3 in File.ReadAllLines("text/tempranks.txt"))
|
||||
{
|
||||
if (line3.Contains(p.name))
|
||||
{
|
||||
string player = line3.Split(' ')[0];
|
||||
int period = Convert.ToInt32(line3.Split(' ')[3]);
|
||||
int minutes = Convert.ToInt32(line3.Split(' ')[4]);
|
||||
int hours = Convert.ToInt32(line3.Split(' ')[5]);
|
||||
int days = Convert.ToInt32(line3.Split(' ')[6]);
|
||||
int months = Convert.ToInt32(line3.Split(' ')[7]);
|
||||
int years = Convert.ToInt32(line3.Split(' ')[8]);
|
||||
Player who = PlayerInfo.Find(player);
|
||||
DateTime ExpireDate = new DateTime(years, months, days, hours, minutes, 0);
|
||||
DateTime tocheck = ExpireDate.AddHours(Convert.ToDouble(period));
|
||||
DateTime tochecknow = DateTime.Now;
|
||||
double datecompare = DateTime.Compare(tocheck, tochecknow);
|
||||
if (datecompare <= 0)
|
||||
Command.all.Find("deltemprank").Use(null, who.name);
|
||||
}
|
||||
|
||||
public static void TRExpiryCheck() {
|
||||
foreach (Player p in PlayerInfo.players) {
|
||||
foreach (string line in File.ReadAllLines("text/tempranks.txt")) {
|
||||
if (!line.Contains(p.name)) continue;
|
||||
string[] args = line.Split(' ');
|
||||
|
||||
int period = Convert.ToInt32(args[3]);
|
||||
int minutes = Convert.ToInt32(args[4]);
|
||||
int hours = Convert.ToInt32(args[5]);
|
||||
int days = Convert.ToInt32(args[6]);
|
||||
int months = Convert.ToInt32(args[7]);
|
||||
int years = Convert.ToInt32(args[8]);
|
||||
|
||||
Player who = PlayerInfo.Find(args[0]);
|
||||
DateTime expire = new DateTime(years, months, days, hours, minutes, 0)
|
||||
.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