public override bool HandleTileEdit(TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle)
        {
            if (this.IsDisposed)
            return false;
              if (base.HandleTileEdit(player, editType, blockType, location, objectStyle))
            return true;

              if (editType == TileEditType.PlaceTile)
            return this.HandleTilePlace(player, blockType, location, objectStyle);
              if (editType == TileEditType.TileKill || editType == TileEditType.TileKillNoItem)
            return this.HandleTileDestruction(player, location);
              if (editType == TileEditType.PlaceWire || editType == TileEditType.PlaceWireBlue || editType == TileEditType.PlaceWireGreen)
            return this.HandleWirePlace(player, location);

              #if DEBUG || Testrun
              if (editType == TileEditType.DestroyWire) {
            player.SendMessage(location.ToString(), Color.Aqua);

            if (!TerrariaUtils.Tiles[location].active())
              return false;

            ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(location);
            player.SendInfoMessage(string.Format(
              "X: {0}, Y: {1}, FrameX: {2}, FrameY: {3}, Origin X: {4}, Origin Y: {5}, Active State: {6}",
              location.X, location.Y, TerrariaUtils.Tiles[location].frameX, TerrariaUtils.Tiles[location].frameY,
              measureData.OriginTileLocation.X, measureData.OriginTileLocation.Y,
              TerrariaUtils.Tiles.ObjectHasActiveState(measureData)
            ));
              }
              #endif

              return false;
        }
        public virtual bool HandleTileEdit(TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle)
        {
            if (this.IsDisposed || this.activeCommandInteractions.Count == 0)
            {
                return(false);
            }

            lock (this.activeCommandInteractionsLock) {
                CommandInteraction interaction;
                // Is the player currently interacting with a command?
                if (!this.activeCommandInteractions.TryGetValue(player, out interaction))
                {
                    return(false);
                }

                if (interaction.TileEditCallback == null)
                {
                    return(false);
                }

                CommandInteractionResult result = interaction.TileEditCallback(player, editType, blockType, location, objectStyle);
                if (interaction.DoesNeverComplete)
                {
                    interaction.ResetTimer();
                }
                else if (result.IsInteractionCompleted)
                {
                    this.activeCommandInteractions.Remove(player);
                }

                return(result.IsHandled);
            }
        }
예제 #3
0
 public TileEditEventArgs(
     TSPlayer player, TileEditType editType, DPoint location, int blockType, int objectStyle
     ) : base(player, location)
 {
     this.EditType    = editType;
     this.BlockType   = blockType;
     this.ObjectStyle = objectStyle;
 }
 public TileEditEventArgs(
     TSPlayer player, TileEditType editType, DPoint location, BlockType blockType, int objectStyle
     )
     : base(player, location)
 {
     this.EditType = editType;
       this.BlockType = blockType;
       this.ObjectStyle = objectStyle;
 }
        public override bool HandleTileEdit(TSPlayer player, TileEditType editType, int blockType, DPoint location, int objectStyle)
        {
            if (this.IsDisposed)
            {
                return(false);
            }
            if (base.HandleTileEdit(player, editType, blockType, location, objectStyle))
            {
                return(true);
            }

            if (editType == TileEditType.PlaceTile)
            {
                return(this.HandleTilePlace(player, blockType, location, objectStyle));
            }
            if (editType == TileEditType.TileKill || editType == TileEditType.TileKillNoItem)
            {
                return(this.HandleTileDestruction(player, location));
            }
            if (editType == TileEditType.PlaceWire || editType == TileEditType.PlaceWireBlue || editType == TileEditType.PlaceWireGreen || editType == TileEditType.PlaceWireYellow)
            {
                return(this.HandleWirePlace(player, location));
            }

      #if DEBUG || Testrun
            if (editType == TileEditType.DestroyWire)
            {
                player.SendMessage(location.ToString(), Color.Aqua);

                if (!TerrariaUtils.Tiles[location].active())
                {
                    return(false);
                }

                ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(location);
                player.SendInfoMessage(string.Format(
                                           "X: {0}, Y: {1}, FrameX: {2}, FrameY: {3}, Origin X: {4}, Origin Y: {5}, Active State: {6} Paint:{7}",
                                           location.X, location.Y, TerrariaUtils.Tiles[location].frameX, TerrariaUtils.Tiles[location].frameY,
                                           measureData.OriginTileLocation.X, measureData.OriginTileLocation.Y,
                                           TerrariaUtils.Tiles.ObjectHasActiveState(measureData), TerrariaUtils.Tiles[location].color()
                                           ));
            }
      #endif

            return(false);
        }
예제 #6
0
        public bool HandleTileEdit(TSPlayer player, TileEditType editType, int blockType, DPoint location, int objectStyle)
        {
            switch (editType)
            {
            case TileEditType.PlaceTile: {
                switch (blockType)
                {
                case AdvancedCircuits.BlockType_WirelessTransmitter:
                    if (
                        AdvancedCircuits.IsComponentWiredByPort(location, new DPoint(1, 1)) &&
                        !this.Metadata.WirelessTransmitters.ContainsKey(location)
                        )
                    {
                        this.Metadata.WirelessTransmitters.Add(location, player.Name);
                    }

                    break;
                }

                break;
            }

            case TileEditType.PlaceWire:
            case TileEditType.PlaceWireBlue:
            case TileEditType.PlaceWireGreen: {
                // Check if we just wired an unregistered component's port.
                foreach (DPoint adjacentTileLocation in AdvancedCircuits.EnumerateComponentPortLocations(location, new DPoint(1, 1)))
                {
                    ITile tile = TerrariaUtils.Tiles[adjacentTileLocation];
                    if (tile.active() && tile.type == AdvancedCircuits.BlockType_WirelessTransmitter)
                    {
                        if (!this.Metadata.WirelessTransmitters.ContainsKey(adjacentTileLocation))
                        {
                            this.Metadata.WirelessTransmitters.Add(adjacentTileLocation, player.Name);
                        }
                    }
                }

                break;
            }

            case TileEditType.TileKill:
            case TileEditType.TileKillNoItem: {
                if (!TerrariaUtils.Tiles[location].active())
                {
                    break;
                }

                switch (TerrariaUtils.Tiles[location].type)
                {
                case TileID.Timers: {
                    if (this.Metadata.ActiveTimers.ContainsKey(location))
                    {
                        this.Metadata.ActiveTimers.Remove(location);
                    }

                    break;
                }

                case TileID.GrandfatherClocks: {
                    ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(location);
                    if (this.Metadata.Clocks.ContainsKey(measureData.OriginTileLocation))
                    {
                        this.Metadata.Clocks.Remove(measureData.OriginTileLocation);
                    }

                    break;
                }

                case AdvancedCircuits.BlockType_Swapper: {
                    if (this.Metadata.Swappers.ContainsKey(location))
                    {
                        this.Metadata.Swappers.Remove(location);
                    }

                    break;
                }

                case AdvancedCircuits.BlockType_ANDGate:
                case AdvancedCircuits.BlockType_ORGate:
                case AdvancedCircuits.BlockType_XORGate: {
                    if (this.Metadata.GateStates.ContainsKey(location))
                    {
                        this.Metadata.GateStates.Remove(location);
                    }

                    break;
                }

                case AdvancedCircuits.BlockType_BlockActivator: {
                    if (this.Metadata.BlockActivators.ContainsKey(location))
                    {
                        this.Metadata.BlockActivators.Remove(location);
                    }

                    break;
                }

                case AdvancedCircuits.BlockType_WirelessTransmitter: {
                    if (this.Metadata.WirelessTransmitters.ContainsKey(location))
                    {
                        this.Metadata.WirelessTransmitters.Remove(location);
                    }

                    break;
                }
                }

                break;
            }
            }

            return(false);
        }
        public override bool HandleTileEdit(
            TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle
            )
        {
            if (this.IsDisposed)
            return false;
              if (base.HandleTileEdit(player, editType, blockType, location, objectStyle))
            return true;

              switch (editType) {
            case TileEditType.PlaceTile: {
              Tile tile = TerrariaUtils.Tiles[location];
              if (tile == null)
            Main.tile[location.X, location.Y] = tile = new Tile();

              WorldGen.PlaceTile(location.X, location.Y, (int)blockType, false, true, -1, objectStyle);
              NetMessage.SendData((int)PacketTypes.Tile, -1, player.Index, string.Empty, 1, location.X, location.Y, (int)blockType, objectStyle);

              if (this.Config.AutoProtectedTiles[(int)blockType])
            this.TryCreateAutoProtection(player, location);

              return true;
            }
            case TileEditType.TileKill:
            case TileEditType.TileKillNoItem: {
              // Is the tile really going to be destroyed or just being hit?
              //if (blockType != 0)
              //  break;

              Tile tile = TerrariaUtils.Tiles[location];
              bool isChest = (tile.type == TileID.Containers || tile.type == TileID.Dressers);
              foreach (ProtectionEntry protection in this.ProtectionManager.EnumerateProtectionEntries(location)) {
            // If the protection is invalid, just remove it.
            if (!TerrariaUtils.Tiles.IsValidCoord(protection.TileLocation)) {
              this.ProtectionManager.RemoveProtection(TSPlayer.Server, protection.TileLocation, false);
              continue;
            }

            Tile protectedTile = TerrariaUtils.Tiles[protection.TileLocation];
            // If the protection is invalid, just remove it.
            if (!protectedTile.active() || protectedTile.type != (int)protection.BlockType) {
              this.ProtectionManager.RemoveProtection(TSPlayer.Server, protection.TileLocation, false);
              continue;
            }

            string tileName = TerrariaUtils.Tiles.GetBlockTypeName((BlockType)protectedTile.type);
            if (
              protection.Owner == player.User.ID || (
                this.Config.AutoDeprotectEverythingOnDestruction &&
                player.Group.HasPermission(ProtectorPlugin.ProtectionMaster_Permission)
              )
            ) {
              if (isChest) {
                bool isBankChest = (protection.BankChestKey != BankChestDataKey.Invalid);
                ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(protection.TileLocation);
                DPoint chestLocation = measureData.OriginTileLocation;
                IChest chest = this.ChestManager.ChestFromLocation(chestLocation);

                if (chest == null)
                  return true;

                if (isBankChest) {
                  this.DestroyBlockOrObject(chestLocation);
                } else {
                  for (int i = 0; i < Chest.maxItems; i++) {
                    if (chest.Items[i].StackSize > 0)
                      return true;
                  }
                }
              }
              this.ProtectionManager.RemoveProtection(player, protection.TileLocation, false);

              if (this.Config.NotifyAutoDeprotections)
                player.SendWarningMessage($"The {tileName} is not protected anymore.");
            } else {
              player.SendErrorMessage($"The {tileName} is protected.");

              if (protection.TradeChestData != null)
                player.SendWarningMessage("If you want to trade with this chest, right click it first.");

              player.SendTileSquare(location);
              return true;
            }
              }

              if (isChest) {
            ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(location);
            DPoint chestLocation = measureData.OriginTileLocation;
            IChest chest = this.ChestManager.ChestFromLocation(chestLocation);
            if (chest != null) {
              // Don't allow removing of non empty chests.
              for (int i = 0; i < Chest.maxItems; i++) {
                if (chest.Items[i].StackSize > 0)
                  return true;
              }

              this.DestroyBlockOrObject(chestLocation);
              return true;
            }
              }

              break;
            }
            case TileEditType.PlaceWire:
            case TileEditType.PlaceWireBlue:
            case TileEditType.PlaceWireGreen:
            case TileEditType.PlaceWireYellow:
            case TileEditType.PlaceActuator:
            case TileEditType.DestroyWire:
            case TileEditType.DestroyWireBlue:
            case TileEditType.DestroyWireGreen:
            case TileEditType.DestroyWireYellow:
            case TileEditType.DestroyActuator:
              if (this.Config.AllowWiringProtectedBlocks)
            break;

              if (this.CheckProtected(player, location, false)) {
            player.SendTileSquare(location);
            return true;
              }

              break;
            case TileEditType.PokeLogicGate:
            case TileEditType.Actuate:
              if (this.CheckProtected(player, location, false)) {
            player.SendTileSquare(location);
            return true;
              }

              break;
              }

              return false;
        }
        public override bool HandleTileEdit(
            TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle
            )
        {
            if (this.IsDisposed)
            return false;
              if (base.HandleTileEdit(player, editType, blockType, location, objectStyle))
            return true;

              switch (editType) {
            case TileEditType.TileKill:
            case TileEditType.TileKillNoItem: {
              // Is the tile really going to be destroyed or just being hit?
              //if (blockType != 0)
              //  break;

              foreach (ProtectionEntry protection in this.ProtectionManager.EnumerateProtectionEntries(location)) {
            // If the protection is invalid, just remove it.
            if (!TerrariaUtils.Tiles.IsValidCoord(protection.TileLocation)) {
              this.ProtectionManager.RemoveProtection(TSPlayer.Server, protection.TileLocation, false);
              continue;
            }

            Tile protectedTile = TerrariaUtils.Tiles[protection.TileLocation];
            // If the protection is invalid, just remove it.
            if (
              !protectedTile.active() ||
              protectedTile.type != (int)protection.BlockType
            ) {
              this.ProtectionManager.RemoveProtection(TSPlayer.Server, protection.TileLocation, false);
              continue;
            }

            string tileName = TerrariaUtils.Tiles.GetBlockTypeName((BlockType)protectedTile.type);
            if (
              protection.Owner == player.User.ID || (
                this.Config.AutoDeprotectEverythingOnDestruction &&
                player.Group.HasPermission(ProtectorPlugin.ProtectionMaster_Permission)
              )
            ) {
              bool isChest = (protectedTile.type == TileID.Containers || protectedTile.type == TileID.Dressers);
              if (isChest) {
                ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(protection.TileLocation);
                DPoint chestLocation = measureData.OriginTileLocation;
                int chestId = Chest.FindChest(chestLocation.X, chestLocation.Y);

                if (chestId != -1) {
                  bool isBankChest = (protection.BankChestKey != BankChestDataKey.Invalid);
                  if (isBankChest) {
                    Chest.DestroyChestDirect(chestLocation.X, chestLocation.Y, chestId);
                    WorldGen.KillTile(location.X, location.Y);
                    TSPlayer.All.SendData(PacketTypes.TileKill, string.Empty, 3, chestLocation.X, chestLocation.Y, 0f, chestId);
                  } else {
                    Chest tChest = Main.chest[chestId];
                    bool isFilled = tChest.item.Any(i => i != null && i.stack > 0);
                    if (isFilled)
                     break; // Do not remove protections of filled chests.
                  }
                }
              }
              this.ProtectionManager.RemoveProtection(player, protection.TileLocation, false);

              if (this.Config.NotifyAutoDeprotections) {
                player.SendWarningMessage(string.Format("The {0} is not protected anymore.", tileName));
              }
            } else {
              player.SendErrorMessage(string.Format("The {0} is protected.", tileName));
              player.SendTileSquare(location);
              return true;
            }
              }

              break;
            }
            case TileEditType.PlaceWire:
            case TileEditType.DestroyWire:
              if (this.Config.AllowWiringProtectedBlocks)
            break;

              if (this.CheckProtected(player, location, false)) {
            player.SendTileSquare(location);
            return true;
              }

              break;
            case TileEditType.PlaceTile: // As of Terraria 1.2.3, this packet should never be sent for chests.
              // Fix: We do not allow chests to be placed on active stone to prevent players from using the chest duplication bugs.
              // Fix2: Don't allow on ice blocks either, you never know.
              /*if (blockType == BlockType.Chest) {
            for (int x = 0; x < 2; x++) {
              DPoint tileBeneathLocation = location.OffsetEx(x, 1);
              if (
                TerrariaUtils.Tiles[tileBeneathLocation].active() && (
                  TerrariaUtils.Tiles[tileBeneathLocation].type == (int)BlockType.ActiveStone ||
                  TerrariaUtils.Tiles[tileBeneathLocation].type == (int)BlockType.IceRodBlock
                )
              ) {
                TSPlayer.All.SendData(PacketTypes.Tile, string.Empty, 0, location.X, location.Y);

                bool dummy;
                ChestStyle chestStyle = TerrariaUtils.Tiles.GetChestStyle(objectStyle, out dummy);
                int itemType = (int)TerrariaUtils.Tiles.GetItemTypeFromChestType(chestStyle);
                Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 32, 32, itemType);

                player.SendErrorMessage("Chests can not be placed on active stone or ice blocks.");

                return true;
              }
            }
              }*/

              break;
              }

              return false;
        }
        // Called after (probably) all other plugin's tile edit handlers.
        public virtual bool HandlePostTileEdit(
            TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle
            )
        {
            if (this.IsDisposed || editType != TileEditType.PlaceTile)
            return false;
              if (!this.Config.AutoProtectedTiles[(int)blockType])
            return false;

              Task.Factory.StartNew(() => {
            Thread.Sleep(150);

            Tile tile = TerrariaUtils.Tiles[location];
            if (!tile.active())
              return;

            try {
              this.ProtectionManager.CreateProtection(player, location, false);

              if (this.Config.NotifyAutoProtections)
            player.SendSuccessMessage(string.Format("This {0} has been protected.", TerrariaUtils.Tiles.GetBlockTypeName((BlockType)tile.type)));
            } catch (PlayerNotLoggedInException) {
              player.SendWarningMessage(string.Format(
            "This {0} will not be protected because you're not logged in.", TerrariaUtils.Tiles.GetBlockTypeName((BlockType)tile.type)
              ));
            } catch (LimitEnforcementException) {
              player.SendWarningMessage(string.Format(
            "This {0} will not be protected because you've reached the protection limit.", TerrariaUtils.Tiles.GetBlockTypeName((BlockType)tile.type)
              ));
            } catch (TileProtectedException) {
              this.PluginTrace.WriteLineError("Error: A block was tried to be auto protected where tile placement should not be possible.");
            } catch (AlreadyProtectedException) {
              this.PluginTrace.WriteLineError("Error: A block was tried to be auto protected on the same position of an existing protection.");
            } catch (Exception ex) {
              this.PluginTrace.WriteLineError("Unexpected exception was thrown during auto protection setup: \n" + ex);
            }
              }, TaskCreationOptions.PreferFairness);

              return false;
        }
        public override bool HandleTileEdit(
            TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle
            )
        {
            if (this.IsDisposed)
            return false;
              if (base.HandleTileEdit(player, editType, blockType, location, objectStyle))
            return true;

              switch (editType) {
            case TileEditType.TileKill:
            case TileEditType.TileKillNoItem: {
              // Is the tile really going to be destroyed or just being hit?
              //if (blockType != 0)
              //  break;

              foreach (ProtectionEntry protection in this.ProtectionManager.EnumerateProtectionEntries(location)) {
            // If the protection is invalid, just remove it.
            if (!TerrariaUtils.Tiles.IsValidCoord(protection.TileLocation)) {
              this.ProtectionManager.RemoveProtection(TSPlayer.Server, protection.TileLocation, false);
              continue;
            }

            Tile protectedTile = TerrariaUtils.Tiles[protection.TileLocation];
            // If the protection is invalid, just remove it.
            if (!protectedTile.active() || protectedTile.type != (int)protection.BlockType) {
              this.ProtectionManager.RemoveProtection(TSPlayer.Server, protection.TileLocation, false);
              continue;
            }

            string tileName = TerrariaUtils.Tiles.GetBlockTypeName((BlockType)protectedTile.type);
            if (
              protection.Owner == player.User.ID || (
                this.Config.AutoDeprotectEverythingOnDestruction &&
                player.Group.HasPermission(ProtectorPlugin.ProtectionMaster_Permission)
              )
            ) {
              bool isChest = (protectedTile.type == TileID.Containers || protectedTile.type == TileID.Dressers);
              if (isChest) {
                ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(protection.TileLocation);
                DPoint chestLocation = measureData.OriginTileLocation;
                int chestId = Chest.FindChest(chestLocation.X, chestLocation.Y);

                if (chestId != -1) {
                  bool isBankChest = (protection.BankChestKey != BankChestDataKey.Invalid);
                  if (isBankChest) {
                    Chest.DestroyChestDirect(chestLocation.X, chestLocation.Y, chestId);
                    WorldGen.KillTile(location.X, location.Y);
                    TSPlayer.All.SendData(PacketTypes.TileKill, string.Empty, 3, chestLocation.X, chestLocation.Y, 0f, chestId);
                  } else {
                    Chest tChest = Main.chest[chestId];
                    bool isFilled = tChest.item.Any(i => i != null && i.stack > 0);
                    if (isFilled)
                      break; // Do not remove protections of filled chests.
                  }
                }
              }
              this.ProtectionManager.RemoveProtection(player, protection.TileLocation, false);

              if (this.Config.NotifyAutoDeprotections)
                player.SendWarningMessage(string.Format("The {0} is not protected anymore.", tileName));
            } else {
              player.SendErrorMessage(string.Format("The {0} is protected.", tileName));
              player.SendTileSquare(location);
              return true;
            }
              }

              break;
            }
            case TileEditType.PlaceWire:
            case TileEditType.DestroyWire:
              if (this.Config.AllowWiringProtectedBlocks)
            break;

              if (this.CheckProtected(player, location, false)) {
            player.SendTileSquare(location);
            return true;
              }

              break;
              }

              return false;
        }
        public override bool HandleTileEdit(
            TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle
            )
        {
            if (this.IsDisposed)
            return false;
              if (base.HandleTileEdit(player, editType, blockType, location, objectStyle))
            return true;

              switch (editType) {
            case TileEditType.TileKill:
            case TileEditType.TileKillNoItem: {
              // Is the tile really going to be destroyed or just being hit?
              if (blockType != 0)
            break;

              // Because Terraria is dumb-assed, TileKill which is usually only sent on a chest being removed, is also sent
              // when the chest is filled but was hit enought times to be removed, thus we have to work around this by checking
              // if there's content in the chest.
              if (TerrariaUtils.Tiles[location].active() && TerrariaUtils.Tiles[location].type == (int)BlockType.Chest) {
            DPoint chestLocation = TerrariaUtils.Tiles.MeasureObject(location).OriginTileLocation;
            int chestIndex = Chest.FindChest(chestLocation.X, chestLocation.Y);
            // Non existing chests are considered empty.
            if (chestIndex != -1) {
              Chest tChest = Main.chest[chestIndex];
              bool isFilled = tChest.item.Any(i => i != null && i.stack > 0);
              if (isFilled) {
                lock (this.WorldMetadata.Protections) {
                  ProtectionEntry protection;
                  if (
                    !this.WorldMetadata.Protections.TryGetValue(chestLocation, out protection) ||
                    protection.BankChestKey == BankChestDataKey.Invalid
                  ) {
                    break;
                  }
                }
              }
            }
              }

              Tile protectedTile = null;
              foreach (ProtectionEntry protection in this.ProtectionManager.EnumerateProtectionEntries(location)) {
            if (!TerrariaUtils.Tiles.IsValidCoord(protection.TileLocation)) {
              this.ProtectionManager.RemoveProtection(TSPlayer.Server, protection.TileLocation, false);
              protectedTile = null;
              continue;
            }
            protectedTile = TerrariaUtils.Tiles[protection.TileLocation];

            // If the protection is invalid, just remove it.
            if (!protectedTile.active() || protectedTile.type != (int)protection.BlockType) {
              this.ProtectionManager.RemoveProtection(TSPlayer.Server, protection.TileLocation, false);
              protectedTile = null;
              continue;
            }

            if (
              protection.Owner == player.UserID || (
                this.Config.AutoDeprotectEverythingOnDestruction &&
                player.Group.HasPermission(ProtectorPlugin.ProtectionMaster_Permission)
              )
            ) {
              this.ProtectionManager.RemoveProtection(player, protection.TileLocation, false);

              if (this.Config.NotifyAutoDeprotections) {
                player.SendWarningMessage(string.Format(
                  "The {0} is not protected anymore.", TerrariaUtils.Tiles.GetBlockTypeName((BlockType)protectedTile.type)
                ));
              }

              protectedTile = null;
              continue;
            }
              }

              if (protectedTile != null) {
            player.SendErrorMessage(string.Format(
              "The {0} is protected.", TerrariaUtils.Tiles.GetBlockTypeName((BlockType)protectedTile.type)
            ));

            player.SendTileSquare(location);
            return true;
              }

              break;
            }
            case TileEditType.PlaceWire:
            case TileEditType.DestroyWire:
              if (this.Config.AllowWiringProtectedBlocks)
            break;

              if (this.CheckProtected(player, location, false)) {
            player.SendTileSquare(location);
            return true;
              }

              break;
            case TileEditType.PlaceTile: // As of Terraria 1.2.3, this packet should never be sent for chests.
              // Fix: We do not allow chests to be placed on active stone to prevent players from using the chest duplication bugs.
              // Fix2: Don't allow on ice blocks either, you never know.
              /*if (blockType == BlockType.Chest) {
            for (int x = 0; x < 2; x++) {
              DPoint tileBeneathLocation = location.OffsetEx(x, 1);
              if (
                TerrariaUtils.Tiles[tileBeneathLocation].active() && (
                  TerrariaUtils.Tiles[tileBeneathLocation].type == (int)BlockType.ActiveStone ||
                  TerrariaUtils.Tiles[tileBeneathLocation].type == (int)BlockType.IceRodBlock
                )
              ) {
                TSPlayer.All.SendData(PacketTypes.Tile, string.Empty, 0, location.X, location.Y);

                bool dummy;
                ChestStyle chestStyle = TerrariaUtils.Tiles.GetChestStyle(objectStyle, out dummy);
                int itemType = (int)TerrariaUtils.Tiles.GetItemTypeFromChestType(chestStyle);
                Item.NewItem(location.X * TerrariaUtils.TileSize, location.Y * TerrariaUtils.TileSize, 32, 32, itemType);

                player.SendErrorMessage("Chests can not be placed on active stone or ice blocks.");

                return true;
              }
            }
              }*/

              break;
              }

              return false;
        }
    public bool HandleTileEdit(TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle) {
      switch (editType) {
        case TileEditType.PlaceTile: {
          switch (blockType) {
            case BlockType.GrandfatherClock:
              this.Metadata.Clocks.Add(new DPoint(location.X, location.Y - 4), new GrandfatherClockMetadata(player.Name));
              break;
            case AdvancedCircuits.BlockType_WirelessTransmitter:
              if (
                AdvancedCircuits.IsComponentWiredByPort(location, new DPoint(1, 1)) &&
                !this.Metadata.WirelessTransmitters.ContainsKey(location)
              )
                this.Metadata.WirelessTransmitters.Add(location, player.Name);

              break;
          }

          break;
        }
        case TileEditType.PlaceWire:
        case TileEditType.PlaceWireBlue:
        case TileEditType.PlaceWireGreen: {
          // Check if we just wired an unregistered component's port.
          foreach (DPoint adjacentTileLocation in AdvancedCircuits.EnumerateComponentPortLocations(location, new DPoint(1, 1))) {
            Tile tile = TerrariaUtils.Tiles[adjacentTileLocation];
            if (tile.active() && tile.type == (int)AdvancedCircuits.BlockType_WirelessTransmitter) {
              if (!this.Metadata.WirelessTransmitters.ContainsKey(adjacentTileLocation))
                this.Metadata.WirelessTransmitters.Add(adjacentTileLocation, player.Name);
            }
          }

          break;
        }
        case TileEditType.TileKill:
        case TileEditType.TileKillNoItem: {
          if (!TerrariaUtils.Tiles[location].active())
            break;

          switch ((BlockType)TerrariaUtils.Tiles[location].type) {
            case BlockType.XSecondTimer: {
              if (this.Metadata.ActiveTimers.ContainsKey(location))
                this.Metadata.ActiveTimers.Remove(location);

              break;
            }
            case BlockType.GrandfatherClock: {
              ObjectMeasureData measureData = TerrariaUtils.Tiles.MeasureObject(location);
              if (this.Metadata.Clocks.ContainsKey(measureData.OriginTileLocation))
                this.Metadata.Clocks.Remove(measureData.OriginTileLocation);

              break;
            }
            case AdvancedCircuits.BlockType_Swapper: {
              if (this.Metadata.Swappers.ContainsKey(location))
                this.Metadata.Swappers.Remove(location);

              break;
            }
            case AdvancedCircuits.BlockType_ANDGate:
            case AdvancedCircuits.BlockType_ORGate:
            case AdvancedCircuits.BlockType_XORGate: {
              if (this.Metadata.GateStates.ContainsKey(location))
                this.Metadata.GateStates.Remove(location);

              break;
            }
            case AdvancedCircuits.BlockType_BlockActivator: {
              if (this.Metadata.BlockActivators.ContainsKey(location))
                this.Metadata.BlockActivators.Remove(location);

              break;
            }
            case AdvancedCircuits.BlockType_WirelessTransmitter: {
              if (this.Metadata.WirelessTransmitters.ContainsKey(location))
                this.Metadata.WirelessTransmitters.Remove(location);

              break;
            }
          }

          break;
        }
      }

      return false;
    }
        public virtual bool HandleTileEdit(TSPlayer player, TileEditType editType, BlockType blockType, DPoint location, int objectStyle)
        {
            if (this.IsDisposed || this.activeCommandInteractions.Count == 0)
            return false;

              lock (this.activeCommandInteractionsLock) {
            CommandInteraction interaction;
            // Is the player currently interacting with a command?
            if (!this.activeCommandInteractions.TryGetValue(player, out interaction))
              return false;

            if (interaction.TileEditCallback == null)
              return false;

            CommandInteractionResult result = interaction.TileEditCallback(player, editType, blockType, location, objectStyle);
            if (interaction.DoesNeverComplete)
              interaction.ResetTimer();
            else if (result.IsInteractionCompleted)
              this.activeCommandInteractions.Remove(player);

            return result.IsHandled;
              }
        }