/ownerreport

/ownerreport

Postby anoniemspy700 » 11 Jan 2014, 23:00

This is a command I was trying to make, joppiesaus helped me out a lot and I just customized it after we talked for nearly an hour for me to understand it :P (now I'm going to try make my own).
The basic idea behind the command is that any player can use /ownerreport or /oreport to report anything they think is unfair or should not have happened. The server owner can check the txt file that is created when he gets back from somewhere. He can then see what importnant things have happened.

Code: Select all
using System;
using System.IO;

namespace MCDzienny
{
public class CmdOwnerreport : Command
{
  public override string name { get { return "ownerreport"; } }
  public override string shortcut { get { return "oreport"; } }
  public override string type { get { return "other"; } }
  public override bool museumUsable { get { return false; } }
  public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

        private string filePath;

        public override void Init()
        {
            this.filePath = Directory.GetCurrentDirectory() + @"\oreport.txt";
            check();
        }

        void check()
        {
            if (File.Exists(filePath)) return;
            else using (File.Create(filePath)) { }
        }

        void log(string s)
        {
            check();

            string readed = "Nothing Yet";
            using (StreamReader read = new StreamReader(filePath))
            {
                readed = read.ReadToEnd();
            }

            using (StreamWriter write = new StreamWriter(filePath))
            {
                write.Write(readed + System.Environment.NewLine + s);
            }

        }

  public override void Use(Player p, string message)
  {
            string[] words = message.Trim().Split(' ');
           
            if (words.Length < 2)
            {
                p.SendMessage("Missing Arguments!");
                Help(p);
                return;
            }

            string problem = message.Replace(words[0] + " ", "");
           
            string who = "Console";
            if (p != null) who = p.PublicName;

            string toLog = DateTime.Now.ToString() + "| Reported by: " + who + " | Solved: " + words[0] + " | Problem: " + problem;
            log(toLog);

            Player.SendMessage(p, "Reported succesfully!");
  }

  public override void Help(Player p)
  {
   Player.SendMessage(p, "/ownerreport <solved = yes | no> <problem> - reports a problem to the owner");
   Player.SendMessage(p, "The problem may also be a conflict, a staff member misbehaving,");
   Player.SendMessage(p, "Or a someone being disrespectfull, or any other rule thats being broken");
  }
}
}


Enjoy!
Join My Lava Survival! [NL]Dutch Lava Survival[NL]
On during day, off during night...(who plays at night?)
User avatar
anoniemspy700
 
Posts: 5
Joined: 08 Jan 2014, 14:13

Re: /ownerreport

Postby lucasds12 » 20 Jan 2014, 17:27

This is very good, there are other /report commands, but this is a another good /report, got to stay that it is pretty good, seems like no errors founded by me, I see you are learning code.
There is only one thing I do in life, that's contributing here.
lucasds12
 
Posts: 334
Joined: 17 Apr 2013, 16:17
Location: In the deep caves.


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 6 guests

cron