public override void Load(bool startup) { command = new CmdCustomModel(); Command.Register(command); OnPlayerConnectEvent.Register(OnPlayerConnect, Priority.Low); OnPlayerDisconnectEvent.Register(OnPlayerDisconnect, Priority.Low); OnJoiningLevelEvent.Register(OnJoiningLevel, Priority.Low); OnJoinedLevelEvent.Register(OnJoinedLevel, Priority.Low); OnSendingModelEvent.Register(OnSendingModel, Priority.Low); OnPlayerCommandEvent.Register(OnPlayerCommand, Priority.Low); // OnEntitySpawnedEvent.Register(OnEntitySpawned, Priority.Low); Directory.CreateDirectory(PublicModelsDirectory); Directory.CreateDirectory(PersonalModelsDirectory); int numModels = CreateMissingCCModels(false); int numPersonalModels = CreateMissingCCModels(true); Logger.Log( LogType.SystemActivity, "CustomModels Loaded with {0} Models and {1} Personal Models", numModels, numPersonalModels ); // initialize because of a late plugin load foreach (Player p in PlayerInfo.Online.Items) { SentCustomModels.TryAdd(p.name, new HashSet <string>(StringComparer.OrdinalIgnoreCase)); ModelNameToIdForPlayer.TryAdd(p.name, new ConcurrentDictionary <string, byte>(StringComparer.OrdinalIgnoreCase)); } }
public override void Unload(bool shutdown) { SentCustomModels.Clear(); ModelNameToIdForPlayer.Clear(); OnPlayerConnectEvent.Unregister(OnPlayerConnect); OnPlayerDisconnectEvent.Unregister(OnPlayerDisconnect); OnJoiningLevelEvent.Unregister(OnJoiningLevel); OnJoinedLevelEvent.Unregister(OnJoinedLevel); OnSendingModelEvent.Unregister(OnSendingModel); OnPlayerCommandEvent.Unregister(OnPlayerCommand); // OnEntitySpawnedEvent.Unregister(OnEntitySpawned); if (command != null) { Command.Unregister(command); command = null; } }
public override void Unload(bool shutdown) { if (dc != null) { dc.Dispose(); } if (!registered) { return; } OnPlayerConnectEvent.Unregister(PlayerConnect); OnPlayerDisconnectEvent.Unregister(PlayerDisconnect); OnPlayerChatEvent.Unregister(PlayerChat); OnPlayerCommandEvent.Unregister(PlayerCommand); OnMessageReceivedEvent.Unregister(DiscordMessage); Command.Unregister(Command.Find("DiscordBot")); }
public override void Load(bool startup) { config.LoadConfig(); if (config.Token == "" || config.ChannelID == "") { Logger.Log(LogType.Warning, "Invalid config! Please setup the Discord bot in discord.properties! (plugin reload required)"); return; } dc = new Discord.Discord(config.Token, config.ChannelID); OnPlayerConnectEvent.Register(PlayerConnect, Priority.Low); OnPlayerDisconnectEvent.Register(PlayerDisconnect, Priority.Low); OnPlayerChatEvent.Register(PlayerChat, Priority.Low); OnPlayerCommandEvent.Register(PlayerCommand, Priority.Low); OnModActionEvent.Register(ModAction, Priority.Low); OnMessageReceivedEvent.Register(DiscordMessage, Priority.Low); Command.Register(new CmdDiscordBot()); registered = true; }
Command GetCommand(ref string cmd, ref string cmdArgs) { if (!CheckCommand(cmd)) { return(null); } Command.Search(ref cmd, ref cmdArgs); byte bindIndex; if (byte.TryParse(cmd, out bindIndex) && bindIndex < CmdBindings.Length) { if (CmdArgsBindings[bindIndex] == null) { SendMessage("No command is bound to: /" + cmd); return(null); } cmd = CmdBindings[bindIndex]; cmdArgs = CmdArgsBindings[bindIndex] + " " + cmdArgs; cmdArgs = cmdArgs.TrimEnd(' '); } OnPlayerCommandEvent.Call(this, cmd, cmdArgs); if (cancelcommand) { cancelcommand = false; return(null); } Command command = Command.all.Find(cmd); if (command == null) { if (Block.Byte(cmd) != Block.Invalid) { cmdArgs = cmd.ToLower(); cmd = "mode"; command = Command.all.FindByName("Mode"); } else { Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmd, cmdArgs); SendMessage("Unknown command \"" + cmd + "\"."); return(null); } } if (!group.CanExecute(command)) { CommandPerms.Find(command.name).MessageCannotUse(this); return(null); } string reason = Command.GetDisabledReason(command.Enabled); if (reason != null) { SendMessage("Command is disabled as " + reason); return(null); } if (level.IsMuseum && !command.museumUsable) { SendMessage("Cannot use this command while in a museum."); return(null); } return(command); }
Command GetCommand(ref string cmdName, ref string cmdArgs, CommandData data) { if (!CheckCommand(cmdName)) { return(null); } Command.Search(ref cmdName, ref cmdArgs); byte bindIndex; if (byte.TryParse(cmdName, out bindIndex) && bindIndex < CmdBindings.Length) { if (CmdBindings[bindIndex] == null) { Message("No command is bound to: %T/" + cmdName); return(null); } CmdBindings[bindIndex].Separate(out cmdName, out cmdArgs); Command.Search(ref cmdName, ref cmdArgs); } OnPlayerCommandEvent.Call(this, cmdName, cmdArgs, data); if (cancelcommand) { cancelcommand = false; return(null); } Command command = Command.Find(cmdName); if (command == null) { if (Block.Parse(this, cmdName) != Block.Invalid) { cmdArgs = cmdName; cmdName = "mode"; command = Command.Find("Mode"); } else { Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmdName, cmdArgs); Message("Unknown command \"" + cmdName + "\"."); return(null); } } if (!CanUse(command)) { CommandPerms.Find(command.name).MessageCannotUse(this); return(null); } string reason = Command.GetDisabledReason(command.Enabled); if (reason != null) { Message("Command is disabled as " + reason); return(null); } if (level != null && level.IsMuseum && !command.museumUsable) { Message("Cannot use %T/{0} %Swhile in a museum.", command.name); return(null); } if (frozen && !command.UseableWhenFrozen) { Message("Cannot use %T/{0} %Swhile frozen.", command.name); return(null); } return(command); }
Command GetCommand(ref string cmdName, ref string cmdArgs, CommandData data) { if (!CheckCommand(cmdName)) { return(null); } string bound; byte bindIndex; if (CmdBindings.TryGetValue(cmdName, out bound)) { // user defined command shortcuts take priority bound.Separate(out cmdName, out cmdArgs); } else if (byte.TryParse(cmdName, out bindIndex) && bindIndex < 10) { // backwards compatibility for old /cmdbind behaviour Message("No command is bound to: &T/" + cmdName); return(null); } Command.Search(ref cmdName, ref cmdArgs); OnPlayerCommandEvent.Call(this, cmdName, cmdArgs, data); if (cancelcommand) { cancelcommand = false; return(null); } Command command = Command.Find(cmdName); if (command == null) { if (Block.Parse(this, cmdName) != Block.Invalid) { cmdArgs = cmdName; cmdName = "mode"; command = Command.Find("Mode"); } else { Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmdName, cmdArgs); Message("Unknown command \"{0}\".", cmdName); return(null); } } if (!CanUse(command)) { CommandPerms.Find(command.name).MessageCannotUse(this); return(null); } string reason = Command.GetDisabledReason(command.Enabled); if (reason != null) { Message("Command is disabled as " + reason); return(null); } if (level != null && level.IsMuseum && !command.museumUsable) { Message("Cannot use &T/{0} &Swhile in a museum.", command.name); return(null); } if (frozen && !command.UseableWhenFrozen) { Message("Cannot use &T/{0} &Swhile frozen.", command.name); return(null); } return(command); }
Command GetCommand(ref string cmd, ref string cmdArgs) { Command.Search(ref cmd, ref cmdArgs); byte bindIndex; if (byte.TryParse(cmd, out bindIndex) && bindIndex < 10) { if (messageBind[bindIndex] == null) { SendMessage("No command is bound to: /" + cmd); return(null); } cmd = cmdBind[bindIndex]; cmdArgs = messageBind[bindIndex] + " " + cmdArgs; cmdArgs = cmdArgs.TrimEnd(' '); } if (OnCommand != null) { OnCommand(cmd, this, cmdArgs); } if (PlayerCommand != null) { PlayerCommand(cmd, this, cmdArgs); } OnPlayerCommandEvent.Call(cmd, this, cmdArgs); if (cancelcommand) { cancelcommand = false; return(null); } Command command = Command.all.Find(cmd); if (command == null) { if (Block.Byte(cmd) != Block.Invalid) { cmdArgs = cmd.ToLower(); cmd = "mode"; command = Command.all.Find("mode"); } else { SendMessage("Unknown command \"" + cmd + "\"."); return(null); } } if (!group.CanExecute(command)) { command.MessageCannotUse(this); return(null); } string reason = Command.GetDisabledReason(command.Enabled); if (reason != null) { SendMessage("Command is disabled as " + reason); return(null); } if (level.IsMuseum && !command.museumUsable) { SendMessage("Cannot use this command while in a museum."); return(null); } return(command); }