Beispiel #1
0
        private void Game_PostInitialize(EventArgs e)
        {
            ServerApi.Hooks.GamePostInitialize.Deregister(this, this.Game_PostInitialize);

            if (!Directory.Exists(ProtectorPlugin.DataDirectory))
            {
                Directory.CreateDirectory(ProtectorPlugin.DataDirectory);
            }

            if (!this.InitConfig())
            {
                return;
            }
            if (!this.InitServerMetdataHandler())
            {
                return;
            }
            if (!this.InitWorldMetdataHandler())
            {
                return;
            }

            this.PluginCooperationHandler = new PluginCooperationHandler(this.Trace);
            this.ChestManager             = new ChestManager(
                this.Trace, this.Config, this.ServerMetadataHandler, this.WorldMetadata);
            this.ProtectionManager = new ProtectionManager(
                this.Trace, this.Config, this.ChestManager, this.ServerMetadataHandler, this.WorldMetadata);

            this.InitUserInteractionHandler();
            this.UserInteractionHandler.EnsureProtectionData(TSPlayer.Server);

            this.hooksEnabled = true;
        }
        public ChestManager(
            PluginTrace pluginTrace, Configuration config, ServerMetadataHandler serverMetadataHandler, WorldMetadata worldMetadata,
            PluginCooperationHandler cooperationHandler
            )
        {
            this.PluginTrace           = pluginTrace;
            this.config                = config;
            this.ServerMetadataHandler = serverMetadataHandler;
            this.WorldMetadata         = worldMetadata;
            this.CooperationHandler    = cooperationHandler;

            this.RefillTimers = new TimerManager(pluginTrace);
            this.RefillTimerCallbackHandler = this.RefillChestTimer_Callback;
        }
        public ChestManager(
            PluginTrace pluginTrace, Configuration config, ServerMetadataHandler serverMetadataHandler, WorldMetadata worldMetadata,
            PluginCooperationHandler cooperationHandler
            )
        {
            this.PluginTrace = pluginTrace;
              this.config = config;
              this.ServerMetadataHandler = serverMetadataHandler;
              this.WorldMetadata = worldMetadata;
              this.CooperationHandler = cooperationHandler;

              this.RefillTimers = new TimerManager(pluginTrace);
              this.RefillTimerCallbackHandler = this.RefillChestTimer_Callback;
        }
Beispiel #4
0
        private void Game_PostInitialize(EventArgs e)
        {
            ServerApi.Hooks.GamePostInitialize.Deregister(this, this.Game_PostInitialize);

            if (!Directory.Exists(ProtectorPlugin.DataDirectory))
            {
                Directory.CreateDirectory(ProtectorPlugin.DataDirectory);
            }

            if (!this.InitConfig())
            {
                return;
            }
            if (!this.InitServerMetdataHandler())
            {
                return;
            }
            if (!this.InitWorldMetdataHandler())
            {
                return;
            }

            this.pluginCooperationHandler = new PluginCooperationHandler(this.Trace);
            this.protectionManager        = new ProtectionManager(
                this.Trace, this.Config, this.ServerMetadataHandler, this.WorldMetadataHandler.Metadata
                );

            this.InitUserInteractionHandler();
            this.UserInteractionHandler.EnsureProtectionData(TSPlayer.Server);

            this.hooksEnabled = true;

            Task.Factory.StartNew(() => {
                // Wait a bit until other plugins might have registered their hooks in PostInitialize.
                Thread.Sleep(1000);

                this.AddPostHooks();
            });
        }
        public UserInteractionHandler(
            PluginTrace trace, PluginInfo pluginInfo, Configuration config, ServerMetadataHandler serverMetadataHandler,
            WorldMetadata worldMetadata, ProtectionManager protectionManager, ChestManager chestManager,
            PluginCooperationHandler pluginCooperationHandler, Func<Configuration> reloadConfigurationCallback
            )
            : base(trace)
        {
            Contract.Requires<ArgumentNullException>(trace != null);
              Contract.Requires<ArgumentException>(!pluginInfo.Equals(PluginInfo.Empty));
              Contract.Requires<ArgumentNullException>(config != null);
              Contract.Requires<ArgumentNullException>(serverMetadataHandler != null);
              Contract.Requires<ArgumentNullException>(worldMetadata != null);
              Contract.Requires<ArgumentNullException>(protectionManager != null);
              Contract.Requires<ArgumentNullException>(pluginCooperationHandler != null);
              Contract.Requires<ArgumentNullException>(reloadConfigurationCallback != null);

              this.PluginInfo = pluginInfo;
              this.Config = config;
              this.ServerMetadataHandler = serverMetadataHandler;
              this.WorldMetadata = worldMetadata;
              this.ChestManager = chestManager;
              this.ProtectionManager = protectionManager;
              this.PluginCooperationHandler = pluginCooperationHandler;
              this.ReloadConfigurationCallback = reloadConfigurationCallback;

              this.PlayerIndexChestDictionary = new Dictionary<int,DPoint>(20);
              this.ChestPlayerIndexDictionary = new Dictionary<DPoint,int>(20);

              #region Command Setup
              base.RegisterCommand(
            new[] { "protector" }, this.RootCommand_Exec, this.RootCommand_HelpCallback
              );
              base.RegisterCommand(
            new[] { "protect", "pt" },
            this.ProtectCommand_Exec, this.ProtectCommand_HelpCallback, ProtectorPlugin.ManualProtect_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "deprotect", "dp" },
            this.DeprotectCommand_Exec, this.DeprotectCommand_HelpCallback, ProtectorPlugin.ManualDeprotect_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "protectioninfo", "ptinfo", "pi" }, this.ProtectionInfoCommand_Exec, this.ProtectionInfoCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "share" }, this.ShareCommand_Exec, this.ShareCommandHelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unshare" }, this.UnshareCommand_Exec, this.UnshareCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "sharepublic" }, this.SharePublicCommand_Exec, this.SharePublicCommandHelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unsharepublic" }, this.UnsharePublicCommand_Exec, this.UnsharePublicCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "sharegroup" }, this.ShareGroupCommand_Exec, this.ShareGroupCommand_HelpCallback,
            ProtectorPlugin.ShareWithGroups_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unsharegroup" }, this.UnshareGroupCommand_Exec, this.UnshareGroup_HelpCallback,
            ProtectorPlugin.ShareWithGroups_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "lockchest", "lchest" },
            this.LockChestCommand_Exec, this.LockChestCommand_HelpCallback, ProtectorPlugin.Utility_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "swapchest", "schest" },
            this.SwapChestCommand_Exec, this.SwapChestCommand_HelpCallback, ProtectorPlugin.Utility_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "refillchest", "rchest" },
            this.RefillChestCommand_Exec, this.RefillChestCommand_HelpCallback, ProtectorPlugin.SetRefillChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "refillchestmany", "rchestmany" },
            this.RefillChestManyCommand_Exec, this.RefillChestManyCommand_HelpCallback, ProtectorPlugin.Utility_Permission
              );
              base.RegisterCommand(
            new[] { "bankchest", "bchest" },
            this.BankChestCommand_Exec, this.BankChestCommand_HelpCallback, ProtectorPlugin.SetBankChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "dumpbankchest", "dbchest" },
            this.DumpBankChestCommand_Exec, this.DumpBankChestCommand_HelpCallback, ProtectorPlugin.DumpBankChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "tradechest", "tchest" },
            this.TradeChestCommand_Exec, this.TradeChestCommand_HelpCallback, ProtectorPlugin.SetTradeChests_Permission,
            allowServer: false
              );
              #endregion

              #if DEBUG
              base.RegisterCommand(new[] { "fc" }, args => {
            for (int i= 0; i < Main.chest.Length; i++) {
              if (i != ChestManager.DummyChestIndex)
            Main.chest[i] = Main.chest[i] ?? new Chest();
            }
              }, requiredPermission: Permissions.maintenance);
              base.RegisterCommand(new[] { "fcnames" }, args => {
            for (int i= 0; i < Main.chest.Length; i++) {
              if (i != ChestManager.DummyChestIndex) {
            Main.chest[i] = Main.chest[i] ?? new Chest();
            Main.chest[i].name = "Chest!";
              }
            }
              }, requiredPermission: Permissions.maintenance);
              #endif
        }
        public UserInteractionHandler(
            PluginTrace trace, PluginInfo pluginInfo, Configuration config, ServerMetadataHandler serverMetadataHandler,
            WorldMetadata worldMetadata, ProtectionManager protectionManager, PluginCooperationHandler pluginCooperationHandler,
            Func<Configuration> reloadConfigurationCallback
            )
            : base(trace)
        {
            Contract.Requires<ArgumentNullException>(trace != null);
              Contract.Requires<ArgumentException>(!pluginInfo.Equals(PluginInfo.Empty));
              Contract.Requires<ArgumentNullException>(config != null);
              Contract.Requires<ArgumentNullException>(serverMetadataHandler != null);
              Contract.Requires<ArgumentNullException>(worldMetadata != null);
              Contract.Requires<ArgumentNullException>(protectionManager != null);
              Contract.Requires<ArgumentNullException>(pluginCooperationHandler != null);
              Contract.Requires<ArgumentNullException>(reloadConfigurationCallback != null);

              this.PluginInfo = pluginInfo;
              this.Config = config;
              this.ServerMetadataHandler = serverMetadataHandler;
              this.WorldMetadata = worldMetadata;
              this.ProtectionManager = protectionManager;
              this.PluginCooperationHandler = pluginCooperationHandler;
              this.ReloadConfigurationCallback = reloadConfigurationCallback;

              #region Command Setup
              base.RegisterCommand(
            new[] { "protector" }, this.RootCommand_Exec, this.RootCommand_HelpCallback
              );
              base.RegisterCommand(
            new[] { "protect", "pt" },
            this.ProtectCommand_Exec, this.ProtectCommand_HelpCallback, ProtectorPlugin.ManualProtect_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "deprotect", "dp" },
            this.DeprotectCommand_Exec, this.DeprotectCommand_HelpCallback, ProtectorPlugin.ManualDeprotect_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "protectioninfo", "ptinfo", "pi" }, this.ProtectionInfoCommand_Exec, this.ProtectionInfoCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "share" }, this.ShareCommand_Exec, this.ShareCommandHelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unshare" }, this.UnshareCommand_Exec, this.UnshareCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "sharepublic" }, this.SharePublicCommand_Exec, this.SharePublicCommandHelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unsharepublic" }, this.UnsharePublicCommand_Exec, this.UnsharePublicCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "sharegroup" }, this.ShareGroupCommand_Exec, this.ShareGroupCommand_HelpCallback,
            ProtectorPlugin.ShareWithGroups_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unsharegroup" }, this.UnshareGroupCommand_Exec, this.UnshareGroup_HelpCallback,
            ProtectorPlugin.ShareWithGroups_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "lockchest", "lchest" },
            this.LockChestCommand_Exec, this.LockChestCommand_HelpCallback, ProtectorPlugin.Utility_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "refillchest", "rchest" },
            this.RefillChestCommand_Exec, this.RefillChestCommand_HelpCallback, ProtectorPlugin.SetRefillChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "refillchestmany", "rchestmany" },
            this.RefillChestManyCommand_Exec, this.RefillChestManyCommand_HelpCallback, ProtectorPlugin.Utility_Permission
              );
              base.RegisterCommand(
            new[] { "bankchest", "bchest" },
            this.BankChestCommand_Exec, this.BankChestCommand_HelpCallback, ProtectorPlugin.SetBankChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "dumpbankchest", "dbchest" },
            this.DumpBankChestCommand_Exec, this.DumpBankChestCommand_HelpCallback, ProtectorPlugin.DumpBankChests_Permission,
            allowServer: false
              );
              #endregion
        }
        private void Game_PostInitialize(EventArgs e)
        {
            ServerApi.Hooks.GamePostInitialize.Deregister(this, this.Game_PostInitialize);

              if (!Directory.Exists(ProtectorPlugin.DataDirectory))
            Directory.CreateDirectory(ProtectorPlugin.DataDirectory);

              if (!this.InitConfig())
            return;
              if (!this.InitServerMetdataHandler())
            return;
              if (!this.InitWorldMetdataHandler())
            return;

              this.pluginCooperationHandler = new PluginCooperationHandler(this.Trace);
              this.protectionManager = new ProtectionManager(
            this.Trace, this.Config, this.ServerMetadataHandler, this.WorldMetadataHandler.Metadata
              );

              this.InitUserInteractionHandler();
              this.UserInteractionHandler.EnsureProtectionData(TSPlayer.Server);

              this.hooksEnabled = true;

              Task.Factory.StartNew(() => {
            // Wait a bit until other plugins might have registered their hooks in PostInitialize.
            Thread.Sleep(1000);

            this.AddPostHooks();
              });
        }